PropertyInfo.GetGetMethod Methode

Definition

Gibt eine MethodInfo zurück, die den get-Accessor für diese Eigenschaft darstellt.

Überlädt

GetGetMethod(Boolean)

Gibt beim Überschreiben in einer abgeleiteten Klasse den öffentlichen oder nicht öffentlichen get-Accessor für diese Eigenschaft zurück.

GetGetMethod()

Gibt den öffentlichen get-Accessor für diese Eigenschaft zurück.

GetGetMethod(Boolean)

Quelle:
PropertyInfo.cs
Quelle:
PropertyInfo.cs
Quelle:
PropertyInfo.cs

Gibt beim Überschreiben in einer abgeleiteten Klasse den öffentlichen oder nicht öffentlichen get-Accessor für diese Eigenschaft zurück.

public:
 abstract System::Reflection::MethodInfo ^ GetGetMethod(bool nonPublic);
public abstract System.Reflection.MethodInfo? GetGetMethod (bool nonPublic);
public abstract System.Reflection.MethodInfo GetGetMethod (bool nonPublic);
abstract member GetGetMethod : bool -> System.Reflection.MethodInfo
Public MustOverride Function GetGetMethod (nonPublic As Boolean) As MethodInfo

Parameter

nonPublic
Boolean

Gibt an, ob ein nicht öffentlicher get-Accessor zurückgegeben werden soll. true, wenn ein nicht öffentlicher Accessor zurückgegeben werden soll, andernfalls false.

Gibt zurück

Ein MethodInfo-Objekt, das den get-Accessor für diese Eigenschaft darstellt, wenn nonPublic den Wert true hat. Gibt null zurück, wenn nonPublic den Wert false hat und der get-Accessor nicht öffentlich ist oder wenn nonPublic den Wert true hat, aber kein get-Accessor vorhanden ist.

Implementiert

Ausnahmen

Die angeforderte Methode ist nicht öffentlich, und der Aufrufer verfügt nicht über die ReflectionPermission zum Reflektieren dieser nicht öffentlichen Methode.

Beispiele

Im folgenden Beispiel wird der öffentliche oder nicht öffentliche get Accessor für die angegebene Eigenschaft angezeigt.

using namespace System;
using namespace System::Reflection;

// Define a property.
public ref class Myproperty
{
private:
   String^ caption;

public:
   Myproperty()
      : caption( "A Default caption" )
   {}


   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

      void set( String^ value )
      {
         if ( caption != value )
         {
            caption = value;
         }
      }

   }

};

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 {0} returns a {1}", Mypropertyinfoa->Name, Mygetmethodinfoa->ReturnType );
   MethodInfo^ Mygetmethodinfob = Mypropertyinfob->GetGetMethod();
   Console::Write( "\nGetAccessor for {0} returns a {1}", Mypropertyinfob->Name, Mygetmethodinfob->ReturnType );
   
   // Display the GetGetMethod without using the MethodInfo.
   Console::Write( "\n{0}.{1} GetGetMethod - {2}", MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->GetGetMethod() );
   Console::Write( "\n{0}.{1} GetGetMethod - {2}", MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->GetGetMethod() );
   return 0;
}
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;
    }
}
Imports System.Reflection

' 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

Hinweise

Diese Eigenschaft ist die , die MethodInfo den Get-Accessor darstellt.

Um die GetGetMethod -Methode zu verwenden, rufen Sie zuerst die -Klasse Typeab. Rufen Sie PropertyInfovon abType. Verwenden Sie aus die PropertyInfoGetGetMethod -Methode.

Gilt für:

GetGetMethod()

Quelle:
PropertyInfo.cs
Quelle:
PropertyInfo.cs
Quelle:
PropertyInfo.cs

Gibt den öffentlichen get-Accessor für diese Eigenschaft zurück.

public:
 System::Reflection::MethodInfo ^ GetGetMethod();
public:
 virtual System::Reflection::MethodInfo ^ GetGetMethod();
public System.Reflection.MethodInfo? GetGetMethod ();
public System.Reflection.MethodInfo GetGetMethod ();
member this.GetGetMethod : unit -> System.Reflection.MethodInfo
abstract member GetGetMethod : unit -> System.Reflection.MethodInfo
override this.GetGetMethod : unit -> System.Reflection.MethodInfo
Public Function GetGetMethod () As MethodInfo

Gibt zurück

Ein MethodInfo-Objekt, das den öffentlichen get-Accessor für diese Eigenschaft darstellt, oder null, wenn der get-Accessor nicht öffentlich oder nicht vorhanden ist.

Implementiert

Hinweise

Dies ist eine einfache Methode, die eine Implementierung für die abstrakte GetGetMethod Methode bereitstellt, deren nonPublic Parameter auf falsefestgelegt ist.

Um die GetGetMethod -Methode zu verwenden, rufen Sie zuerst die -Klasse Typeab. Rufen Sie PropertyInfovon abType. Verwenden Sie aus die PropertyInfoGetGetMethod -Methode.

Gilt für: