The title may sound a little strange, so I’ll try to explain my problem:
Lets say I have a class that holds some Information:
class InfoHolder
{
public int MyInfo1 {get; set;}
public int MyInfo2 { get; set; }
}
Then I have another class, that does something with an info:
class InfoGUIRepresenter
{
// Display an int in some kind of GUI
// Allow the user to change the int via the GUI
}
Now I would need two objects of the representer class, to expose my Info-class to the user: One representer for each of the two infos. To achieve that it would be nice to pass each of the properties as some kind of “parameter” to my representer classes.
But of course that’s not possible in C#. Another solution would be to pass the names of the properties and then use reflection to access them – not very nice!
Is there any solution to this? Maybe some kind of architecture that addresses this kind problem?
Thanks!
One option is to pass two delegates – one for the setter and one for the getter:
Then your
InfoGUIRepresenterconstructor would take aFunc<int>and anAction<int>. (Or you could make the representer generic, for different types of property.)