A
Alexander Walker
Hello
I would like to write a method that allows me to pass a reference to an instance
of a class, the name of a property of that class and a value to set that
property to, the method would then set the property of the instance to the value
here is an example of what the method might look like
public void SetProperty(object instance, string property, object value)
{
//TODO: set the named property of the instance with the value
}
The method could be called like this
SetProperty(myClassInstance, "MyProperty", "My Value");
How would such a method be written? how do you access the members of an instance
in a late bound manner, or is it even possible to pass a reference to the actual
property like so
SetProperty(myClassInstance, myClassInstance.MyProperty, "The Value");
Where the method is not taking the value of myClassInstance.MyProperty but the
reference to the actual property so that it can set its value, is this possible?
Thanks
Alex
I would like to write a method that allows me to pass a reference to an instance
of a class, the name of a property of that class and a value to set that
property to, the method would then set the property of the instance to the value
here is an example of what the method might look like
public void SetProperty(object instance, string property, object value)
{
//TODO: set the named property of the instance with the value
}
The method could be called like this
SetProperty(myClassInstance, "MyProperty", "My Value");
How would such a method be written? how do you access the members of an instance
in a late bound manner, or is it even possible to pass a reference to the actual
property like so
SetProperty(myClassInstance, myClassInstance.MyProperty, "The Value");
Where the method is not taking the value of myClassInstance.MyProperty but the
reference to the actual property so that it can set its value, is this possible?
Thanks
Alex