PropertyInfo.GetGetMethod Methode

Definitie

Retourneert een MethodInfo weergave van de get toegangsfunctie voor deze eigenschap.

Overloads

Name Description
GetGetMethod()

Retourneert de openbare get toegangsfunctie voor deze eigenschap.

GetGetMethod(Boolean)

Wanneer deze wordt overschreven in een afgeleide klasse, wordt de openbare of niet-openbare get toegangsfunctie voor deze eigenschap geretourneerd.

GetGetMethod()

Retourneert de openbare get toegangsfunctie voor deze eigenschap.

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

Retouren

Een MethodInfo object dat de openbare get toegangsrechten voor deze eigenschap vertegenwoordigt, of null als de get toegangsobject niet openbaar is of niet bestaat.

Implementeringen

Opmerkingen

Dit is een handige methode die een implementatie biedt voor de abstracte GetGetMethod methode met de nonPublic parameter die is ingesteld op false.

Als u de GetGetMethod methode wilt gebruiken, moet u eerst de klasse Typeophalen. TypeHaal de PropertyInfo. Gebruik de methode vanuit de PropertyInfoGetGetMethod methode.

Van toepassing op

GetGetMethod(Boolean)

Wanneer deze wordt overschreven in een afgeleide klasse, wordt de openbare of niet-openbare get toegangsfunctie voor deze eigenschap geretourneerd.

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

Parameters

nonPublic
Boolean

Hiermee wordt aangegeven of een niet-openbare get toegangsfunctie moet worden geretourneerd. true als een niet-openbare toegangsfunctie moet worden geretourneerd; anders, false.

Retouren

Een MethodInfo object dat de get toegangsobject voor deze eigenschap vertegenwoordigt, als nonPublic dat het is true. Retourneert null of nonPublic wel false en de get toegangsfunctie niet openbaar is of als nonPublic er true geen get toegangsrechten bestaan.

Implementeringen

Uitzonderingen

De aangevraagde methode is niet openbaar en de aanroeper hoeft ReflectionPermission niet na te denken over deze niet-openbare methode.

Voorbeelden

In het volgende voorbeeld wordt de openbare of niet-openbare get toegangsfunctie voor de opgegeven eigenschap weergegeven.

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

Opmerkingen

Deze eigenschap is het MethodInfo vertegenwoordigen van de get-accessor.

Als u de GetGetMethod methode wilt gebruiken, moet u eerst de klasse Typeophalen. TypeHaal de PropertyInfo. Gebruik de methode vanuit de PropertyInfoGetGetMethod methode.

Van toepassing op