Hello Ventuzians!
THE FORUMS ARE CLOSED!

Please join our discord server HERE!! << click me :D

We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server

Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!

.NET reflection array get/set

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

Post Reply
bashy

.NET reflection array get/set

Post by bashy » 11 Jun 2015, 08:38

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

Post Reply