Okay, I have a class of complex structure, let's say it's object looks like this:
object theClass
{
object smallerClass1
{
field A
field B
}
object smallerClass2
{
object smallerClass3
{
field C
}
field D
field E
}
field F
}
Each field can be of any value-type.
I also have an interface that consist of a Form. This form contains a panel, that may or may not contain more panels, that may or may not contain more panels, that may or may not contain more panels and so forth. Each panel can contain any number of textboxes that represent the fields in the upper object. Like so:
Form form
{
panel panel1
{
textbox D
textbox C
}
panel panel2
{
panel panel3
{
textbox A
textbox F
}
textbox E
}
}
So not all fields have to necessarily be represented (e.g. field B is missing in this particular case).
Panels are object that take other panels and/or textboxes as parameters Textboxes take fields as parameters (they are both extensions of the panel/textbox class).
And the form gets constructed accordingly.
Now here's the problem. I need the changes in the textboxes to directly reflect in the values of the fields. If a textbox is changed, the field it pulled the data from has to be updated with a new value (I can handle type conversion on lost focus event and just revert last change if the types don't match). It's not necessary to update textbox with fields since fields will be constant (unless changed via textbox).
However, I have no way of passing a reference to my object (and/or any objects it contains) to make a method in my textbox class that would change the field when appropriate.
I have trouble of setting up a reflection since I'm working with undefined (generic?) types in the textbox. Data binding is a problem too since I have no way of passing the reference of the object to unlimited number of nested objects (it only works for first level of depth with a lambda functions, any deeper and I'm binding it to parameter objects instead the actual ones).
So how can I deal with this without having to construct and designate textbox for every and each field? I might construct a separate classes for every type I encounter which would enable me to solve this via reflection, but I hope there is a more elegant solution to this since reflections are basically cheating in this case.
Any ideas?
Aucun commentaire:
Enregistrer un commentaire