Example 1
As we know there's the concept of computed columns in databases where a column is computed based on adjacent columns' values.
The problem is that computed columns can't relate to other rows than current.
Example 2
Then we have spreadsheets (ie. Excel) where a cell can have a formula. This is similar to computed column, but more powerful. A formula can be related to any cell (or set of them) in the spreadsheet and not just current row/column as in RDB.
The problem
The concept of computed (or auto-updated values) is great but how can I do something similar in a set of values/objects in C#?
I would like to create a list (or array) of values where each of them is related to some other (or set of) value in the same list? It's like spreadsheet cell values... Change a value and related ones change along (and the whole related subtree values as well).
Is there a concept like that in C#?
How am I about to do this in the most clever way? I know I could have a LinkedList
of objects where object's properties' values would relate to other objects in the same list and get evaluated whenever value gets accessed (evaluation on demand). This may mean that several (all ancestor nodes) get evaluated along the way. Is there a better way that would work more like spreadsheet cells where they get evaluated first and then accessed individually (propagated evaluation)?
This should of course be applicable to multidimensional arrays as well.
This concept is called Reactive Programming. .NET has something called Reactive Extensions that would allow you to achieve what you have described. Specifically you need to use something called Behavior