PropertyInfo.GetGetMethod メソッド
このプロパティの get アクセサを表す MethodInfo を返します。
オーバーロードの一覧
このプロパティのパブリックな get アクセサを返します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Function GetGetMethod() As MethodInfo
派生クラスによってオーバーライドされた場合に、このプロパティのパブリックまたは非パブリックな get アクセサを返します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public MustOverride Function GetGetMethod(Boolean) As MethodInfo
[JScript] public abstract function GetGetMethod(Boolean) : MethodInfo;
使用例
指定したプロパティのパブリックまたは非パブリックの 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()
*/
参照
PropertyInfo クラス | PropertyInfo メンバ | System.Reflection 名前空間