Tuesday, May 28, 2013

Accessing Values Using Reflection in C#

Hi,


Follow the below code.




// get type of class Calculator from just loaded assembly

Type calcType = testAssembly.GetType("Test.Calculator");



// create instance of class Calculator

object calcInstance = Activator.CreateInstance(calcType);



// get info about property: public double Number

PropertyInfo numberPropertyInfo = calcType.GetProperty("Number");





// get value of property: public double Number

double value = (double)numberPropertyInfo.GetValue(calcInstance, null);


Syed Amjad Sr. Silverlight Developer yahoo : syedamjad6736@yahoo.com skype : syedamjad.0786


No comments:

Post a Comment