M
Mark
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(object oTargetObject, string strPropname, object
oProperty)
{
System.Type myType = oTargetObject.GetType();
System.Reflection.PropertyInfo[] properties = myType.GetProperties();
foreach(System.Reflection.PropertyInfo pi in properties)
{
if (pi.CanWrite && pi.Name == strPropname)
{
pi.SetValue(oTargetObject, 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(object oTargetObject, string strPropname, object
oProperty)
{
System.Type myType = oTargetObject.GetType();
System.Reflection.PropertyInfo[] properties = myType.GetProperties();
foreach(System.Reflection.PropertyInfo pi in properties)
{
if (pi.CanWrite && pi.Name == strPropname)
{
pi.SetValue(oTargetObject, oProperty, null);
}
}
}