PropertyInfo.GetAccessors Method
.NET Framework 1.1
Returns an array of the get and set accessors on this property.
Overload List
Returns an array whose elements reflect the public get, set, and other accessors of the property reflected by the current instance.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetAccessors() As MethodInfo()
[C#] public MethodInfo[] GetAccessors();
[C++] public: MethodInfo* GetAccessors() [];
[JScript] public function GetAccessors() : MethodInfo[];
Returns an array whose elements reflect the public and, if specified, non-public get, set, and other accessors of the property reflected by the current instance.
Supported by the .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[];
Example
The following example displays the accessors of the specified property.
[Visual Basic] 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) */
See Also
PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace