Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

PropertyInfo.GetGetMethod Method

Returns a MethodInfo representing the get accessor for this property.

Overload List

Returns the public get accessor for this property.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetGetMethod() As MethodInfo
[C#] public MethodInfo GetGetMethod();
[C++] public: MethodInfo* GetGetMethod();
[JScript] public function GetGetMethod() : MethodInfo;

When overridden in a derived class, returns the public or non-public get accessor for this property.

Supported by the .NET Compact Framework.

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

Example

The following example displays the public or non-public get accessor for the specified property.

[Visual Basic] 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

' Define a property.
Public Class Myproperty
    Private myCaption As String = "A Default caption"

    Public Property Caption() As String
        Get
            Return myCaption
        End Get
        Set(ByVal Value As String)
            If myCaption <> value Then
                myCaption = value
            End If
        End Set
    End Property
End Class

Class Mypropertyinfo

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyInfo")

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

        ' Get and display the GetGetMethod Method for each property.
        Dim Mygetmethodinfoa As MethodInfo = Mypropertyinfoa.GetGetMethod()
        Console.WriteLine("GetAccessor for " & _
           Mypropertyinfoa.Name & " returns a " & _
           Mygetmethodinfoa.ReturnType.ToString())
        Dim Mygetmethodinfob As MethodInfo = Mypropertyinfob.GetGetMethod()
        Console.WriteLine("GetAccessor for " & _
           Mypropertyinfob.Name & " returns a " & _
           Mygetmethodinfob.ReturnType.ToString())

        ' Display the GetGetMethod without using the MethodInfo.
        Console.WriteLine(MyTypea.FullName & "." & _
           Mypropertyinfoa.Name & " GetGetMethod - " & _
           Mypropertyinfoa.GetGetMethod().ToString())
        Console.WriteLine(MyTypeb.FullName & "." & _
           Mypropertyinfob.Name & " GetGetMethod - " & _
           Mypropertyinfob.GetGetMethod().ToString())
        Return 0
    End Function
End Class

[C#] 
using System;
using System.Reflection;
 
// Define 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" + MyTypea.FullName + "." + Mypropertyinfoa.Name
            + " GetGetMethod - " + Mypropertyinfoa.GetGetMethod());
        Console.Write ("\n" + MyTypeb.FullName + "." + Mypropertyinfob.Name
            + " GetGetMethod - " + Mypropertyinfob.GetGetMethod());
        return 0;
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;

// Define a property.
public __gc class Myproperty   
{
private:
    String* caption;
public:
    Myproperty() : caption(S"A Default caption") {}
    __property String* get_Caption() {
        return caption;
    }
    __property void set_Caption(String* value) {
        if(caption!=value) {
            caption = value;
        }
    }

};

int main()
{
    Console::WriteLine (S"\nReflection.PropertyInfo");

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

    // Get and display the GetGetMethod method for each property.
    MethodInfo* Mygetmethodinfoa = Mypropertyinfoa->GetGetMethod();
    Console::Write (S"\nGetAccessor for {0} returns a {1}",
        Mypropertyinfoa->Name, Mygetmethodinfoa->ReturnType);
    MethodInfo* Mygetmethodinfob = Mypropertyinfob->GetGetMethod();
    Console::Write (S"\nGetAccessor for {0} returns a {1}",
        Mypropertyinfob->Name, Mygetmethodinfob->ReturnType);

    // Display the GetGetMethod without using the MethodInfo.
    Console::Write (S"\n{0}.{1} GetGetMethod - {2}",
        MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->GetGetMethod());
    Console::Write (S"\n{0}.{1} GetGetMethod - {2}",
        MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->GetGetMethod());
    return 0;
}

[JScript] 
import System;
import System.Reflection;

//Make a property
public class Myproperty   
{
   private var caption : String = "A Default caption";
   public function get Caption() : String {
       return caption;
   }
   public function set Caption(value:String) {
       if(caption!=value) caption = value;
   }
}

class Mypropertyinfo
{
   public static function Main() : void
      {
      Console.WriteLine ("\nReflection.PropertyInfo");

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

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

      //Display the GetGetMethod without using the MethodInfo
      Console.Write ("\n" + MyTypea.FullName + "." + Mypropertyinfoa.Name
          + " GetGetMethod - " + Mypropertyinfoa.GetGetMethod());
      Console.Write ("\n" + MyTypeb.FullName + "." + Mypropertyinfob.Name
          + " GetGetMethod - " + Mypropertyinfob.GetGetMethod());
   }
}
Mypropertyinfo.Main();
/*
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 get_Caption()
System.Reflection.MethodInfo.MemberType GetGetMethod - System.Reflection.MemberTypes get_MemberType()
*/

See Also

PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace

Show:
© 2014 Microsoft