現在のインスタンスがリフレクションしているプロパティの、パブリックな get アクセサ、 set アクセサ、およびその他のアクセサをリフレクションする要素で構成される配列を返します。非パブリック アクセサを含めるよう指定することもできます。
Overloads Public MustOverride Function GetAccessors( _
ByVal nonOverloads Public As Boolean _) As MethodInfo()
[C#]
public abstract MethodInfo[] GetAccessors(boolnonPublic);
[C++]
public: virtual MethodInfo* GetAccessors(boolnonPublic) [] = 0;
[JScript]
public abstract function GetAccessors(
nonPublic : Boolean) : MethodInfo[];
パラメータ
- nonPublic
MethodInfo 配列で非パブリック メソッドを返すかどうかを示します。非パブリック メソッドを含める場合は true 。それ以外の場合は false 。
戻り値
現在のインスタンスがリフレクションしているプロパティの get アクセサ、 set アクセサ、およびその他のアクセサをリフレクションする要素で構成される MethodInfo オブジェクトの配列。 nonPublic が true の場合、この配列はパブリックと非パブリック両方の get アクセサ、 set アクセサ、およびその他のアクセサを格納します。 nonPublic が false の場合、この配列はパブリックな get アクセサ、 set アクセサ、およびその他のアクセサだけを格納します。指定した参照可能範囲でアクセサが見つからなかった場合、このメソッドは 0 要素の配列を返します。
解説
GetAccessors メソッドを使用するには、最初に Type クラスを取得します。そして、その Type から PropertyInfo を取得します。 PropertyInfo から、 GetAccessors メソッドを使用します。
使用例
指定したプロパティのアクセサを表示する例を次に示します。
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.
Dim MyType As Type = Type.GetType("Myproperty")
Dim Mypropertyinfo As PropertyInfo = MyType.GetProperty("Caption")
' Get the public GetAccessors method.
Dim Mymethodinfoarray As MethodInfo() = _
Mypropertyinfo.GetAccessors(True)
Console.Write(ControlChars.CrLf & "There are " & _
Mymethodinfoarray.Length & " accessors (public).")
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.
Type MyType = Type.GetType("Myproperty");
PropertyInfo Mypropertyinfo = MyType.GetProperty("Caption");
// Get the public GetAccessors method.
MethodInfo[] Mymethodinfoarray = Mypropertyinfo.GetAccessors(true);
Console.Write ("\nThere are "
+ Mymethodinfoarray.Length + " accessors (public).");
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.
Type* MyType = Type::GetType(S"Myproperty");
PropertyInfo* Mypropertyinfo = MyType->GetProperty(S"Caption");
// Get the public GetAccessors method.
MethodInfo* Mymethodinfoarray[] = Mypropertyinfo->GetAccessors(true);
Console::Write (S"\nThere are {0} accessors (public).", __box(Mymethodinfoarray->Length));
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
var MyType : Type = Type.GetType("Myproperty");
var Mypropertyinfo : PropertyInfo = MyType.GetProperty("Caption");
//Get the public GetAccessors Method
var Mymethodinfoarray : MethodInfo[] = Mypropertyinfo.GetAccessors(true);
Console.Write ("\nThere are "
+ Mymethodinfoarray.Length + "accessors (public)");
}
}
Mypropertyinfo.Main();
/*
Produces the following output
Reflection.PropertyInfo
There are 2 accessors (public)
*/
必要条件
プラットフォーム: 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 (関連する列挙体)
参照
PropertyInfo クラス | PropertyInfo メンバ | System.Reflection 名前空間 | PropertyInfo.GetAccessors オーバーロードの一覧