Page 1 of 1

.NET reflection array get/set

Posted: 11 Jun 2015, 08:38
by bashy
Hi,

i can easily get and set float values through reflection

Code: Select all

	
Type ownType = this.GetType();
PropertyInfo infos = ownType.GetProperty(property, BindingFlags.Instance | BindingFlags.NonPublic);
float tempFloat = 0.1f;

if( info.PropertyType.Equals(tempFloat.GetType()))
{
    info.SetValue(this, tempFloat);
    float f = (float) info.GetValue(this);
    Ventuz.Kernel.VLog.Info("float: "+f);
}
on int and int[]

Code: Select all

if( info.PropertyType.Equals(tempInt.GetType()))
{

    info.SetValue(this, tempInt );
    int i = (int) info.GetValue(this);
    Ventuz.Kernel.VLog.Info("int: " + i);
}
...however i get:

09:07 11.06.2015 Info : : System.ArgumentException: Property set method not found.
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at Script.OnMethod1(Int32 arg)


what am I doing wrong?

bashy