A
andrea
I want to setup properties value to an object created by reference.
I do the following.
T t = Activator.CreateInstance<T>();
Type newItem = typeof(T);
newItem.GetProperty("PropertyA").SetValue(t, "Hello", null);
It works fine, but I see that there is a GetProperties method that returns
all properties available for a certain
type, and I suppose that instead calling a getproperty every time like the
code above, modifying the value to the
array of PropertyInfos it should be faster and with less memory consuming.
Unfortunately when I try to do something like that
PropertyInfors[] pi = newItem.GetProperties(MyBindingValues);
pi.SetValue("Hello", 0);
the compiler at run-time say that I cannot do something like that and throw
an InvalidArgumentCastException.
I was looking for some sample over the net, but nothing usefull. Someone
can let me understand?
Thank you
Andre
I do the following.
T t = Activator.CreateInstance<T>();
Type newItem = typeof(T);
newItem.GetProperty("PropertyA").SetValue(t, "Hello", null);
It works fine, but I see that there is a GetProperties method that returns
all properties available for a certain
type, and I suppose that instead calling a getproperty every time like the
code above, modifying the value to the
array of PropertyInfos it should be faster and with less memory consuming.
Unfortunately when I try to do something like that
PropertyInfors[] pi = newItem.GetProperties(MyBindingValues);
pi.SetValue("Hello", 0);
the compiler at run-time say that I cannot do something like that and throw
an InvalidArgumentCastException.
I was looking for some sample over the net, but nothing usefull. Someone
can let me understand?
Thank you
Andre