Tim Smith

Tim Smith

  • NA
  • 1
  • 0

Using the contents of a string variable to access an instance of a class and a public property

May 20 2009 11:00 AM

I would like to be able to access an object and a specific public property using the contents of a string. 

So, I would have something like this

public class MyClass

{

public System.String prop1 { get; set; }

public System.String prop2 { get; set; }

}

and in code something like this:

MyClass c = new MyClass();

c.prop1 = "Value of property 1";

c.prop2 = "Value of property 2";

System.String s = "MyClass.prop1";

 

How can I use the string s to get the value of property (results would be "Value of proeprty 1")

Thanks - Tim