Mono Class Library: System.Security.Permissions Namespace

System.Security.Permissions.ReflectionPermissionAttribute Class

Used to declaratively specify security actions to control access to non-public types using reflection. [Edit]

See Also: ReflectionPermissionAttribute Members

System.Object
     System.Attribute
          System.Security.Permissions.SecurityAttribute
               System.Security.Permissions.CodeAccessSecurityAttribute
                    System.Security.Permissions.ReflectionPermissionAttribute

[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.All, AllowMultiple=true, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ReflectionPermissionAttribute : CodeAccessSecurityAttribute

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

Note:

The level of access to non-public types and members is specified using the ReflectionPermissionAttribute.Flags property and the System.Security.Permissions.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, System.Security.Permissions.ReflectionPermission.

The allowable System.Security.Permissions.ReflectionPermissionAttribute targets are determined by the System.Security.Permissions.SecurityAction passed to the constructor.

[Edit]

Example

The following example shows a declarative request for access to non-public members of loaded assemblies. The 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)]

Requirements

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0