Mega Code Archive

 
Categories / C# / Reflection
 

Searches for the specified property, using the specified binding constraints

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);         }     } }