PropertyInfo.GetAccessors Method (Boolean)
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.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Parameters
- nonPublic
- Type: System.Boolean
Indicates whether non-public methods should be returned in the MethodInfo array. true if non-public methods are to be included; otherwise, false.
Return Value
Type: System.Reflection.MethodInfo[]An array of MethodInfo objects whose elements reflect the get, set, and other accessors of the property reflected by the current instance. If nonPublic is true, this array contains public and non-public get, set, and other accessors. If nonPublic is false, this array contains only public get, set, and other accessors. If no accessors with the specified visibility are found, this method returns an array with zero (0) elements.
Implements
_PropertyInfo.GetAccessors(Boolean)The following example displays the accessors of the specified property.
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; } }
- ReflectionPermission
when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.