How to find Object property and set it's value

by admin 16. July 2008 10:44

Sometimes you may want to find your object property and set it's value. To do this try something like this:

MyObject myObject = new MyObject(); string propertyName = "MyPropertyName"; bool myValue = true;
Type type = this.GetType();
System.Reflection.PropertyInfo property = type.GetProperty(propertyName);
if (property != null)
    System.ComponentModel.TypeDescriptor.GetProperties(typeof(MyObject))[propertyName].SetValue(myObject, myValue);

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

c#

Comments are closed

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar