PropertyInfo.GetGetMethod Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengembalikan yang MethodInfo mewakili get aksesor untuk properti ini.
Overload
| Nama | Deskripsi |
|---|---|
| GetGetMethod(Boolean) |
Saat ditimpa di kelas turunan, mengembalikan aksesor publik atau non-publik |
| GetGetMethod() |
Mengembalikan aksesor publik |
GetGetMethod(Boolean)
- Sumber:
- PropertyInfo.cs
- Sumber:
- PropertyInfo.cs
- Sumber:
- PropertyInfo.cs
- Sumber:
- PropertyInfo.cs
- Sumber:
- PropertyInfo.cs
Saat ditimpa di kelas turunan, mengembalikan aksesor publik atau non-publik get untuk properti ini.
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
Menunjukkan apakah aksesor non-publik get harus dikembalikan.
true jika aksesor non-publik akan dikembalikan; jika tidak, false.
Mengembalikan
Objek MethodInfo yang get mewakili aksesor untuk properti ini, jika nonPublic adalah true. Mengembalikan null jika nonPublic adalah false dan get aksesor non-publik, atau jika nonPublic tidak ada trueget aksesor.
Penerapan
Pengecualian
Metode yang diminta bersifat non-publik dan pemanggil tidak harus ReflectionPermission merefleksikan metode non-publik ini.
Contoh
Contoh berikut menampilkan aksesor publik atau non-publik get untuk properti yang ditentukan.
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
Keterangan
Properti ini adalah MethodInfo yang mewakili get accessor.
Untuk menggunakan metode , pertama-tama GetGetMethod dapatkan kelas Type.
TypeDari , dapatkan PropertyInfo.
PropertyInfoDari , gunakan GetGetMethod metode .
Berlaku untuk
GetGetMethod()
- Sumber:
- PropertyInfo.cs
- Sumber:
- PropertyInfo.cs
- Sumber:
- PropertyInfo.cs
- Sumber:
- PropertyInfo.cs
- Sumber:
- PropertyInfo.cs
Mengembalikan aksesor publik get untuk properti ini.
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
Mengembalikan
Objek MethodInfo yang mewakili aksesor publik get untuk properti ini, atau null jika get aksesor non-publik atau tidak ada.
Penerapan
Keterangan
Ini adalah metode kenyamanan yang menyediakan implementasi untuk metode abstrak GetGetMethod dengan parameter yang nonPublic diatur ke false.
Untuk menggunakan metode , pertama-tama GetGetMethod dapatkan kelas Type.
TypeDari , dapatkan PropertyInfo.
PropertyInfoDari , gunakan GetGetMethod metode .