次の方法で共有


PropertyInfo.GetAccessors メソッド

このプロパティの get アクセサと set アクセサの配列を返します。

オーバーロードの一覧

現在のインスタンスがリフレクションしているプロパティの、パブリックな get アクセサ、 set アクセサ、およびその他のアクセサをリフレクションする要素で構成される配列を返します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function GetAccessors() As MethodInfo()

[C#] public MethodInfo[] GetAccessors();

[C++] public: MethodInfo* GetAccessors() [];

[JScript] public function GetAccessors() : MethodInfo[];

現在のインスタンスがリフレクションしているプロパティの、パブリックな get アクセサ、 set アクセサ、およびその他のアクセサをリフレクションする要素で構成される配列を返します。非パブリック アクセサを含めるよう指定することもできます。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public MustOverride Function GetAccessors(Boolean) As MethodInfo()

[C#] public abstract MethodInfo[] GetAccessors(bool);

[C++] public: virtual MethodInfo* GetAccessors(bool) [] = 0;

[JScript] public abstract function GetAccessors(Boolean) : MethodInfo[];

使用例

指定したプロパティのアクセサを表示する例を次に示します。

 
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)
*/

参照

PropertyInfo クラス | PropertyInfo メンバ | System.Reflection 名前空間