Using reflection to set properties.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Suresh

    #1

    Using reflection to set properties.

    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 SetPropertyValu e(Object target, string
    property_name(a s 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
  • Jon Skeet

    #2
    Re: Using reflection to set properties.

    Suresh <sureshpasala@h otmail.com> wrote:[color=blue]
    > 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 SetPropertyValu e(Object target, string
    > property_name(a s the text or width), object propertyvalue)
    > {
    > target - get type;[/color]

    Type type = target.GetType( );
    [color=blue]
    > type- property of given name;[/color]

    PropertyInfo prop = type.GetPropert y (name);
    [color=blue]
    > use reflection to set the value;[/color]

    prop.SetValue (target, propertyValue, null);
    [color=blue]
    > }[/color]
    [color=blue]
    > Can also please suggest some good tutorials on reflection.[/color]

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

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...