PropertyInfo.GetGetMethod Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne un MethodInfo représentant l’accesseur get pour cette propriété.
Surcharges
| Nom | Description |
|---|---|
| GetGetMethod() |
Retourne l’accesseur public |
| GetGetMethod(Boolean) |
En cas de substitution dans une classe dérivée, retourne l’accesseur public ou non public |
GetGetMethod()
Retourne l’accesseur public get pour cette propriété.
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
Retours
Objet MethodInfo représentant l’accesseur public get pour cette propriété, ou null si l’accesseur get n’est pas public ou n’existe pas.
Implémente
Remarques
Il s’agit d’une méthode pratique qui fournit une implémentation pour la méthode abstraite GetGetMethod avec le nonPublic paramètre défini sur false.
Pour utiliser la GetGetMethod méthode, commencez par obtenir la classe Type. À partir de la Type, obtenir le PropertyInfo. À partir du PropertyInfo, utilisez la GetGetMethod méthode.
S’applique à
GetGetMethod(Boolean)
En cas de substitution dans une classe dérivée, retourne l’accesseur public ou non public get pour cette propriété.
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
Paramètres
- nonPublic
- Boolean
Indique si un accesseur non public get doit être retourné.
true si un accesseur non public doit être retourné ; sinon, false.
Retours
Objet MethodInfo représentant l’accesseur get de cette propriété, le cas échéanttruenonPublic. Retourne null si nonPublic est false et que l’accesseur get n’est pas public, ou s’il nonPublictrue n’existe pas get d’accesseurs.
Implémente
Exceptions
La méthode demandée n’est pas publique et l’appelant n’a ReflectionPermission pas à réfléchir à cette méthode non publique.
Exemples
L’exemple suivant affiche l’accesseur public ou non public get pour la propriété spécifiée.
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
Remarques
Cette propriété est la MethodInfo représentation de l’accesseur get.
Pour utiliser la GetGetMethod méthode, commencez par obtenir la classe Type. À partir de la Type, obtenir le PropertyInfo. À partir du PropertyInfo, utilisez la GetGetMethod méthode.