派生クラスによってオーバーライドされた場合に、このプロパティのパブリックまたは非パブリックな get アクセサを返します。
Overloads Public MustOverride Function GetGetMethod( _
ByVal nonOverloads Public As Boolean _) As MethodInfo
[C#]
public abstract MethodInfo GetGetMethod(boolnonPublic);
[C++]
public: virtual MethodInfo* GetGetMethod(boolnonPublic) = 0;
[JScript]
public abstract function GetGetMethod(
nonPublic : Boolean) : MethodInfo;
パラメータ
- nonPublic
非パブリックな get アクセサを返すかどうかを示します。非パブリック アクセサを返す場合は true 。それ以外の場合は false 。
戻り値
nonPublic が true の場合は、このプロパティの get アクセサを表す MethodInfo オブジェクト。 nonPublic が false で get アクセサが非パブリックの場合、または nonPublic が true でも get アクセサがない場合は、 null 参照 (Visual Basic では Nothing) を返します。
例外
例外の種類 | 条件 |
---|---|
SecurityException | 要求されたメソッドが非パブリックで、呼び出し元には、この非パブリック メソッドにリフレクションするための ReflectionPermission がありません。 |
解説
このプロパティは、get アクセサを表す MethodInfo です。
GetGetMethod メソッドを使用するには、最初に Type クラスを取得します。そして、その Type から PropertyInfo を取得します。最後に PropertyInfo から、 GetGetMethod メソッドを使用します。
使用例
指定したプロパティのパブリックまたは非パブリックの get アクセサを表示する例を次に示します。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
' 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
[C#]
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;
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
// Define a property.
public __gc class Myproperty
{
private:
String* caption;
public:
Myproperty() : caption(S"A Default caption") {}
__property String* get_Caption() {
return caption;
}
__property void set_Caption(String* value) {
if(caption!=value) {
caption = value;
}
}
};
int main()
{
Console::WriteLine (S"\nReflection.PropertyInfo");
// Get the type and PropertyInfo for two separate properties.
Type* MyTypea = Type::GetType(S"Myproperty");
PropertyInfo* Mypropertyinfoa = MyTypea->GetProperty(S"Caption");
Type* MyTypeb = Type::GetType(S"System.Reflection.MethodInfo");
PropertyInfo* Mypropertyinfob = MyTypeb->GetProperty(S"MemberType");
// Get and display the GetGetMethod method for each property.
MethodInfo* Mygetmethodinfoa = Mypropertyinfoa->GetGetMethod();
Console::Write (S"\nGetAccessor for {0} returns a {1}",
Mypropertyinfoa->Name, Mygetmethodinfoa->ReturnType);
MethodInfo* Mygetmethodinfob = Mypropertyinfob->GetGetMethod();
Console::Write (S"\nGetAccessor for {0} returns a {1}",
Mypropertyinfob->Name, Mygetmethodinfob->ReturnType);
// Display the GetGetMethod without using the MethodInfo.
Console::Write (S"\n{0}.{1} GetGetMethod - {2}",
MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->GetGetMethod());
Console::Write (S"\n{0}.{1} GetGetMethod - {2}",
MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->GetGetMethod());
return 0;
}
[JScript]
import System;
import System.Reflection;
//Make a property
public class Myproperty
{
private var caption : String = "A Default caption";
public function get Caption() : String {
return caption;
}
public function set Caption(value:String) {
if(caption!=value) caption = value;
}
}
class Mypropertyinfo
{
public static function Main() : void
{
Console.WriteLine ("\nReflection.PropertyInfo");
//Get the type and PropertyInfo for two separate properties
var MyTypea : Type = Type.GetType("Myproperty");
var Mypropertyinfoa : PropertyInfo = MyTypea.GetProperty("Caption");
var MyTypeb : Type = Type.GetType("System.Reflection.MethodInfo");
var Mypropertyinfob : PropertyInfo = MyTypeb.GetProperty("MemberType");
//Get and display the GetGetMethod Method for each property
var Mygetmethodinfoa : MethodInfo = Mypropertyinfoa.GetGetMethod();
Console.Write ("\nGetAccessor for " + Mypropertyinfoa.Name
+ " returns a " + Mygetmethodinfoa.ReturnType);
var Mygetmethodinfob : MethodInfo = 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());
}
}
Mypropertyinfo.Main();
/*
Produces the following output
Reflection.PropertyInfo
GetAccessor for Caption returns a System.String
GetAccessor for MemberType returns a System.Reflection.MemberTypes
Myproperty.Caption GetGetMethod - System.String get_Caption()
System.Reflection.MethodInfo.MemberType GetGetMethod - System.Reflection.MemberTypes get_MemberType()
*/
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
.NET Framework セキュリティ:
- ReflectionPermission (Type.InvokeMember などの機構を通じて遅延バインディングで呼び出すときに必要なアクセス許可) ReflectionPermissionFlag.MemberAccess (関連する列挙体)
- ReflectionPermission (非パブリック メソッドをリフレクションするために必要なアクセス許可) ReflectionPermissionFlag.TypeInformation (関連する列挙体)
参照
PropertyInfo クラス | PropertyInfo メンバ | System.Reflection 名前空間 | PropertyInfo.GetGetMethod オーバーロードの一覧