NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

PropertyInfo.GetGetMethod (Boolean)

Returns the Get-accessor for this property.

[Visual Basic]
Overloads MustOverride Public Function GetGetMethod( _
   ByVal nonPublic As Boolean _
) As MethodInfo
[C#]
public abstract MethodInfo GetGetMethod(
   bool nonPublic
);
[C++]
public: virtual MethodInfo* GetGetMethod(
   bool nonPublic
) = 0;
[JScript]
public abstract function GetGetMethod(
   nonPublic : Boolean
) : MethodInfo;

Parameters

nonPublic
Indicates whether the accessor should be returned if it is non-public. True to include non-public methods. False to indicate only public methods.

Return Value

Value Condition
A MethodInfo object representing the Get accessor for this property. The set accessor is public. nonPublic

is true and non-public methods can be returned.

null nonPublic is false and the Get accessor is non-public.

nonPublic is true, but no Get accessors exist.

Remarks

This property is the MethodInfo representing the Get Accessor.

To use the GetGetMethod method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetGetMethod method.

Example [C#]

[C#]

//Make a property
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()
      {
      Console.WriteLine ("\nReflection.PropertyInfo");

      //Get the type and PropertyInfo for two separate properties
      Type MyTypea = Type.GetType("Myproperty");
      PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Caption");
      Type MyTypeb = Type.GetType("System.Reflection.MethodInfo");
      PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("MemberType");

      //Get and display the GetGetMethod Method for each property
      MethodInfo Mygetmethodinfoa = Mypropertyinfoa.GetGetMethod();
      Console.Write ("\nGetAccessor for " + Mypropertyinfoa.Name
         + " returns a " + Mygetmethodinfoa.ReturnType);
      MethodInfo Mygetmethodinfob = Mypropertyinfob.GetGetMethod();
      Console.Write ("\nGetAccessor for " + Mypropertyinfob.Name
         + " returns a " + Mygetmethodinfob.ReturnType);

      //Display the GetGetMethod without using the MethodInfo
      Console.Write ("\n\n" + MyTypea.FullName + "." + Mypropertyinfoa.Name
          + " GetGetMethod - " + Mypropertyinfoa.GetGetMethod());
      Console.Write ("\n" + MyTypeb.FullName + "." + Mypropertyinfob.Name
          + " GetGetMethod - " + Mypropertyinfob.GetGetMethod());
      return 0;
   }
}

Produces the following output

Reflection.PropertyInfo
GetAccessor for Caption returns a System.String
GetAccessor for MemberType returns a System.Reflection.MemberTypes
Myproperty.Caption GetGetMethod - System.String GetCaption ()
System.Reflection.MethodInfo.MemberType GetGetMethod - System.Reflection.MemberTypes GetMemberType ()

See Also

PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace | PropertyInfo.GetGetMethod Overload List