public sealed class ReflectionPermissionAttribute : CodeAccessSecurityAttribute
Object
Attribute
SecurityAttribute
CodeAccessSecurityAttribute
ReflectionPermissionAttribute
mscorlib
Reflection
Used to declaratively specify security actions to control access to non-public types using reflection.
[Note: The level of access to non-public types and members is specified using the System.Security.Permissions.ReflectionPermissionAttribute.Flags property and the ReflectionPermissionFlag enumeration.The security information declared by a security attribute is stored in the metadata of the attribute target, and is accessed by the system at run-time. Security attributes are used for declarative security only. For imperative security, use the corresponding permission class, ReflectionPermission.
The allowable ReflectionPermissionAttribute targets are determined by the SecurityAction passed to the constructor.
]
The following example shows a declarative request for access to non-public members of loaded assemblies. The System.Security.Permissions.SecurityAction.RequestMinimum security action indicates that this is the minimum permission required for the target assembly to be able to execute.
[assembly:ReflectionPermissionAttribute(SecurityAction.RequestMinimum, MemberAccess=true)]
The following example shows how to demand that the calling code has unrestricted access to non-public types. Demands are typically made to protect methods or classes from malicious code.
[ReflectionPermissionAttribute(SecurityAction.Demand, Unrestricted=true)]
AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple=true, Inherited=false)
System.Security.Permissions Namespace
ReflectionPermissionAttribute Constructors
ReflectionPermissionAttribute Constructor
ReflectionPermissionAttribute Methods
ReflectionPermissionAttribute.CreatePermission Method
ReflectionPermissionAttribute Properties
public ReflectionPermissionAttribute(SecurityAction action);
Constructs and initializes a new instance of the ReflectionPermissionAttribute class with the specified SecurityAction value.
- action
- A SecurityAction value.
Exception Type Condition ArgumentException action is not a valid SecurityAction value.
System.Security.Permissions.ReflectionPermissionAttribute Class, System.Security.Permissions Namespace
public override IPermission CreatePermission();
Returns a new ReflectionPermission that contains the security information of the current instance.
A new ReflectionPermission object with the security information of the current instance.
[Note: Applications typically do not call this method; it is intended for use by the system.The security information described by a security attribute is stored in the metadata of the attribute target, and is accessed by the system at run-time. The system uses the object returned by this method to convert the security information of the current instance into the form stored in metadata.
This method overrides System.Security.Permissions.SecurityAttribute.CreatePermission.
]
System.Security.Permissions.ReflectionPermissionAttribute Class, System.Security.Permissions Namespace
public ReflectionPermissionFlag Flags { get; set; }
Gets or sets levels of access to non-public types using reflection.
One or more of the ReflectionPermissionFlag values.
[Note: To specify multiple ReflectionPermissionFlag values for a set operation, use the bitwise OR operator.]
System.Security.Permissions.ReflectionPermissionAttribute Class, System.Security.Permissions Namespace