PropertyInfo.GetGetMethod Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce un oggetto MethodInfo che rappresenta la get funzione di accesso per questa proprietà.
Overload
| Nome | Descrizione |
|---|---|
| GetGetMethod() |
Restituisce la funzione di accesso pubblica |
| GetGetMethod(Boolean) |
Quando sottoposto a override in una classe derivata, restituisce la funzione di accesso pubblica o non pubblica |
GetGetMethod()
Restituisce la funzione di accesso pubblica get per questa proprietà.
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
Valori restituiti
Oggetto MethodInfo che rappresenta la funzione di accesso pubblica get per questa proprietà oppure null se la get funzione di accesso non è pubblica o non esiste.
Implementazioni
Commenti
Si tratta di un metodo pratico che fornisce un'implementazione per il metodo astratto GetGetMethod con il nonPublic parametro impostato su false.
Per usare il GetGetMethod metodo , ottenere prima di tutto la classe Type.
TypeDa ottenere .PropertyInfo
PropertyInfoDa usare il GetGetMethod metodo .
Si applica a
GetGetMethod(Boolean)
Quando sottoposto a override in una classe derivata, restituisce la funzione di accesso pubblica o non pubblica get per questa proprietà.
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
Parametri
- nonPublic
- Boolean
Indica se deve essere restituita una funzione di accesso non pubblica get .
true se deve essere restituita una funzione di accesso non pubblica; in caso contrario, false.
Valori restituiti
Oggetto MethodInfo che rappresenta la get funzione di accesso per questa proprietà, se nonPublic è true. Restituisce se è e la get funzione di accesso non è pubblica oppure se nonPublic è true ma non esiste alcuna get funzione di accesso.falsenonPublicnull
Implementazioni
Eccezioni
Il metodo richiesto non è pubblico e il chiamante non deve ReflectionPermission riflettere su questo metodo non pubblico.
Esempio
Nell'esempio seguente viene visualizzata la funzione di accesso pubblica o non pubblica get per la proprietà specificata.
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
Commenti
Questa proprietà rappresenta MethodInfo la funzione di accesso get.
Per usare il GetGetMethod metodo , ottenere prima di tutto la classe Type.
TypeDa ottenere .PropertyInfo
PropertyInfoDa usare il GetGetMethod metodo .