PropertyInfo.GetGetMethod 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个 MethodInfo 表示 get 此属性的访问器。
重载
| 名称 | 说明 |
|---|---|
| GetGetMethod(Boolean) |
在派生类中重写时,返回此属性的公共或非公共 |
| GetGetMethod() |
返回此属性的公共 |
GetGetMethod(Boolean)
- Source:
- PropertyInfo.cs
- Source:
- PropertyInfo.cs
- Source:
- PropertyInfo.cs
- Source:
- PropertyInfo.cs
- Source:
- PropertyInfo.cs
在派生类中重写时,返回此属性的公共或非公共 get 访问器。
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
参数
- nonPublic
- Boolean
指示是否应返回非公共 get 访问器。
true 如果要返回非公共访问器,则为 ;否则,为 false.
返回
一个 MethodInfo 对象,表示 get 此属性的访问器(如果 nonPublic 为 true)。 返回 null is nonPublic 和false访问器是get非公共访问器,或者如果nonPublic不存在true但不存在get访问器。
实现
例外
请求的方法为非公共方法,调用方不必 ReflectionPermission 反映此非公共方法。
示例
以下示例显示指定属性的公共或非公共 get 访问器。
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
注解
此属性表示 MethodInfo get 访问器。
若要使用该方法 GetGetMethod ,请先获取类 Type。 从中 Type获取 PropertyInfo。 从中PropertyInfoGetGetMethod,使用该方法。
适用于
GetGetMethod()
- Source:
- PropertyInfo.cs
- Source:
- PropertyInfo.cs
- Source:
- PropertyInfo.cs
- Source:
- PropertyInfo.cs
- Source:
- PropertyInfo.cs
返回此属性的公共 get 访问器。
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
返回
表示MethodInfo此属性的公共访问器的对象,或者get访问null器为非公共get访问器或不存在。
实现
注解
这是一种便捷的方法,它为抽象 GetGetMethod 方法 nonPublic 提供了一个实现,参数设置为 false。
若要使用该方法 GetGetMethod ,请先获取类 Type。 从中 Type获取 PropertyInfo。 从中PropertyInfoGetGetMethod,使用该方法。