F
fj
I am wondering if anyone has this same problem and what's the solution.
I am assigning values to an object, for example,
ObjEntityPerson.Edit[0].Item.KeyValue = "12345";
However, the Edit[] might be null, Edit[0] and Item might be null.
Eventually I end up with check each object, if null then initialize it, then
assign it a value.
I want use reflection to write a function like
public Object InitIfNull(byRef Object obj, Type MyType)
{
//Check if obj if null
if( obj == null)
{
ConstructorInfo ctor = typeof(MyType).GetConstructor();
InstanceDescriptor desc = new InstanceDescriptor(ctor, new object [] {});
//bad code, I have to do my research, but anyways, you get an idea. Get the
constructor and create the object.
}
}
My question is is it possible to give any object like
ObjEntityPerson.Edit[0].Item.KeyValue, can I create the object in a
hierarchy?
Thanks
-fj
I am assigning values to an object, for example,
ObjEntityPerson.Edit[0].Item.KeyValue = "12345";
However, the Edit[] might be null, Edit[0] and Item might be null.
Eventually I end up with check each object, if null then initialize it, then
assign it a value.
I want use reflection to write a function like
public Object InitIfNull(byRef Object obj, Type MyType)
{
//Check if obj if null
if( obj == null)
{
ConstructorInfo ctor = typeof(MyType).GetConstructor();
InstanceDescriptor desc = new InstanceDescriptor(ctor, new object [] {});
//bad code, I have to do my research, but anyways, you get an idea. Get the
constructor and create the object.
}
}
My question is is it possible to give any object like
ObjEntityPerson.Edit[0].Item.KeyValue, can I create the object in a
hierarchy?
Thanks
-fj