//Get type of MyClass
Type myType = Type.GetType("MyNamespace.MyClass");
//Get PropertyInfo for property SomeProperty
PropertyInfo pi = myType.GetProperty("SomeProperty");
//Display property value on console.
//Because it's static you can pass nulls for both object and index
Console.WriteLine("Value of my property is: " +
pi.GetValue(null, null));
Tuesday, 1 July 2008
Accessing static properties using C# reflections
Subscribe to:
Post Comments (Atom)
2 comments:
May be a little explanation - where you defined static property ??
The static property "SomeProperty" is defined in class MyNamespace.MyClass. If no reflections required it could be accessed like this:
MyNamespace.MyClass.SomeProperty
Post a Comment