PropertyInfo.GetGetMethod Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
A tulajdonsághoz tartozó tartozékot MethodInfo adja get vissza.
Túlterhelések
| Name | Description |
|---|---|
| GetGetMethod(Boolean) |
Ha egy származtatott osztályban felül van bírálva, a tulajdonság nyilvános vagy nem nyilvános |
| GetGetMethod() |
A tulajdonság nyilvános |
GetGetMethod(Boolean)
- Forrás:
- PropertyInfo.cs
- Forrás:
- PropertyInfo.cs
- Forrás:
- PropertyInfo.cs
- Forrás:
- PropertyInfo.cs
- Forrás:
- PropertyInfo.cs
Ha egy származtatott osztályban felül van bírálva, a tulajdonság nyilvános vagy nem nyilvános get tartozékát adja vissza.
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
Paraméterek
- nonPublic
- Boolean
Azt jelzi, hogy nem nyilvános get tartozékot kell-e visszaadni.
truenem nyilvános tartozék visszaadása esetén; egyéb esetben. false
Válaszok
A MethodInfo tulajdonság tartozékát get képviselő objektum, ha nonPublic igen true. Visszaadja null , ha nonPublic igen, false és a get tartozék nem nyilvános, vagy ha nonPublic igen true , de nem get létezik tartozék.
Megvalósítás
Kivételek
A kért metódus nem nyilvános, és a hívónak nem kell ReflectionPermission tükröznie ezt a nem nyilvános metódust.
Példák
Az alábbi példa a megadott tulajdonság nyilvános vagy nem nyilvános get tartozékát jeleníti meg.
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
Megjegyzések
Ez a tulajdonság a MethodInfo lekéréses tartozékot jelöli.
A metódus használatához GetGetMethod először szerezze be az osztályt Type.
TypeA helyről szerezze be a PropertyInfo. Használja a PropertyInfometódust.GetGetMethod
A következőre érvényes:
GetGetMethod()
- Forrás:
- PropertyInfo.cs
- Forrás:
- PropertyInfo.cs
- Forrás:
- PropertyInfo.cs
- Forrás:
- PropertyInfo.cs
- Forrás:
- PropertyInfo.cs
A tulajdonság nyilvános get tartozékát adja vissza.
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
Válaszok
A MethodInfo tulajdonság nyilvános get tartozékát képviselő objektum, vagy null ha a get tartozék nem nyilvános, vagy nem létezik.
Megvalósítás
Megjegyzések
Ez egy kényelmi módszer, amely az absztrakt GetGetMethod metódus implementálását biztosítja a nonPublic paraméter beállításával false.
A metódus használatához GetGetMethod először szerezze be az osztályt Type.
TypeA helyről szerezze be a PropertyInfo. Használja a PropertyInfometódust.GetGetMethod