Hey guys,
I need to assign an array to a field. I dont know the fields type, but I do have a reference to an instance and the name of the field. I can assume the array can be casted to the fields type. Can this be done?
Bas
Edit:
Hopefully this code will clarify what Im trying to do, this causes an exception in assign:
class MyClass
{
static void Main()
{
MyClass t = new MyClass();
A a = new A();
C[] c = new C[] {new B()};
t.Assign(a, "field", c);
}
void Assign(object obj, string field, object[] value)
{
// crashes
obj.GetType().GetField(field).SetValue(obj, value);
}
}
class A
{
public B[] field;
}
class B : C { }
class C { }