Using reflection to set properties.

  • Thread starter Thread starter Suresh
  • Start date Start date
S

Suresh

Hi,
How to set the TextBox text property using Reflection.
Or to that matter any property of a control.
Iam having trouble writing a function of the style

public static void SetPropertyValue(Object target, string
property_name(as the text or width), object propertyvalue)
{
target - get type;
type- property of given name;
use reflection to set the value;
}
Can also please suggest some good tutorials on reflection.

Thanks
Suresh
 
Suresh said:
How to set the TextBox text property using Reflection.
Or to that matter any property of a control.
Iam having trouble writing a function of the style

public static void SetPropertyValue(Object target, string
property_name(as the text or width), object propertyvalue)
{
target - get type;

Type type = target.GetType();
type- property of given name;

PropertyInfo prop = type.GetProperty (name);
use reflection to set the value;

prop.SetValue (target, propertyValue, null);
Can also please suggest some good tutorials on reflection.

I'm afraid I don't know of any specifically, but the MSDN class and
method descriptions are pretty good.
 
Back
Top