Hi there,
I'm trying to create a function to dynamically set a property from a class.
The idea is to get a general function that works for every class. Although
this function works for classes i created myself, and for standard classes,
this function does not seem to work for classes from webreferences (wsdl).
I wonder why...
This is my code:
public void setProperty(obj ect oTargetObject, string strPropname, object
oProperty)
{
System.Type myType = oTargetObject.G etType();
System.Reflecti on.PropertyInfo[] properties = myType.GetPrope rties();
foreach(System. Reflection.Prop ertyInfo pi in properties)
{
if (pi.CanWrite && pi.Name == strPropname)
{
pi.SetValue(oTa rgetObject, oProperty, null);
}
}
}
I'm trying to create a function to dynamically set a property from a class.
The idea is to get a general function that works for every class. Although
this function works for classes i created myself, and for standard classes,
this function does not seem to work for classes from webreferences (wsdl).
I wonder why...
This is my code:
public void setProperty(obj ect oTargetObject, string strPropname, object
oProperty)
{
System.Type myType = oTargetObject.G etType();
System.Reflecti on.PropertyInfo[] properties = myType.GetPrope rties();
foreach(System. Reflection.Prop ertyInfo pi in properties)
{
if (pi.CanWrite && pi.Name == strPropname)
{
pi.SetValue(oTa rgetObject, oProperty, null);
}
}
}
Comment