How can I set a property value by name in runtime?

How can I set an object's property value by name in runtime


Answer this question

How can I set a property value by name in runtime?

  • Scott Hathaway

    Thanks!Smile

  • Lck

    Here's a snippet that shows how to set the width of a form during runtime.

       


        Form form = new Form();
        form.Width = 100;

        Type formType = form.GetType();
        System.Reflection.PropertyInfo propInfo = formType.GetProperty("Width");
        if (propInfo != null)
        {
            propInfo.SetValue(form, 200, new object[] { });
        }
       
        Debug.Assert(form.Width == 200);


     



  • How can I set a property value by name in runtime?