Dynamically set property

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);

}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top