I have this code that I am currently adapting to use nested entity (entity framework). I have an entity which contains 2 property which are 2 children entities.
The first step was to read the metadata on both classes, starting from the first classes, building up a list of properties. This is completed. Now I need to iterate over my object to find the good property to do the DataBinding.
This is what I currently have :
variables example :
datasource = namespace.A
propriete = {System.Nullable`1[System.Int32] count}
propriete.DeclaringType {Name = "prop2" FullName = "Namespace.Metadata.prop2"}
code :
if (this.datasource != null)
{
var y = (T)this.datasource;
var propList = typeof(T).GetProperties();
if (propList.ToList().Contains(propriete))
{
TextBox.Text = DataBinder.Eval(y, propriete.Name).ToString();
}
else
{
TextBox.Text = ":( need child-support!";
}
}
My main problem is that my object type is unknown till runtime (Type T) so I have no idea on how to find my field.
Quick model :
Class A {
public B prop1;
public C prop2;
}
Class B {
int count;
string name;
}
Class C {
int count;
string name;
}
A.prop1.count = 1;
A.prop1.name = "a";
A.prop2.count = 2;
A.prop2.name = "b";
Right now, my property name are all unique (more specific than count/name), but I expect them to be the same (count/name) at some point.
propriete will probably have to "filter" with DeclaringType/ReflectedType for non-unique name.
A brute-force solution considering unique name, although not elegant, might be accepted.
Extra problem : propriete
use another partial class contains in the metadata
namespace while datasource
use the main class.
(... And if you are curious as to what this system does : It builds a html table (with .net controls) based on an entity based on this metadata.entity dataAttribute.)