using System;
using System.Reflection;
class MyClass
{
private int myProperty;
public int MyProperty
{
get
{
return myProperty;
}
set
{
myProperty=value;
}
}
}
public class MyTypeClass
{
public static void Main(string[] args)
{
try
{
Type myType=typeof(MyClass);
PropertyInfo myPropInfo = myType.GetProperty("MyProperty", BindingFlags.Public | BindingFlags.Instance);
Console.WriteLine("{0} is a property of MyClass.", myPropInfo.Name);
}
catch(NullReferenceException e)
{
Console.WriteLine("MyProperty does not exist in MyClass." +e.Message);
}
}
}