Mega Code Archive

 
Categories / C# / Reflection
 

Get the set accessor for this property

using System; using System.Reflection; public class Myproperty    {     private string caption = "A Default caption";     public string Caption     {         get{return caption;}         set {if(caption!=value) {caption = value;}         }     } } class Mypropertyinfo {     public static int Main()     {         Type MyTypea = Type.GetType("Myproperty");         PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Caption");         Type MyTypeb = Type.GetType("System.Text.StringBuilder");         PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("Length");         MethodInfo Mygetmethodinfoa = Mypropertyinfoa.GetSetMethod();         Console.WriteLine (Mypropertyinfoa.Name);         Console.WriteLine (Mygetmethodinfoa.ReturnType);         MethodInfo Mygetmethodinfob = Mypropertyinfob.GetSetMethod();         Console.Write (Mygetmethodinfob.ReturnType);         Console.WriteLine(MyTypea.FullName);         Console.WriteLine(Mypropertyinfoa.GetSetMethod());         Console.WriteLine(MyTypeb.FullName );         Console.WriteLine(Mypropertyinfob.Name);         Console.WriteLine(Mypropertyinfob.GetSetMethod());         return 0;     } }