Returns an array of the public, and/or non-public Get and Set accessors on this property.
[Visual Basic] Overloads MustOverride Public Function GetAccessors( _ ByVal nonPublic As Boolean _ ) As MethodInfo () [C#] public abstract MethodInfo[] GetAccessors( bool nonPublic ); [C++] public: virtual MethodInfo* GetAccessors( bool nonPublic ) [] = 0; [JScript] public abstract function GetAccessors( nonPublic : Boolean ) : MethodInfo[];
Value | Condition |
---|---|
An array of MethodInfo objects representing the public or non-public accessors. | Matching, public or non-public, accessors exist on this property. |
An empty MethodInfo array. | Matching accessors do not exist on this property. |
The array will be empty if no accessors are found.
To use the GetAccessors method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetAccessors method.
[C#]
//Make 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.Count + "accessors (public)"); return 0; } } Produces the following output Reflection.PropertyInfo There are 2 accessors (public)
PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace | PropertyInfo.GetAccessors Overload List