System.Security.Permissions.ReflectionPermissionAttribute Class

public sealed class ReflectionPermissionAttribute : CodeAccessSecurityAttribute

Base Types

Object
  Attribute
    SecurityAttribute
      CodeAccessSecurityAttribute
        ReflectionPermissionAttribute

Assembly

mscorlib

Library

Reflection

Summary

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

Description

[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.

]

Example

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)]

Attributes

AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple=true, Inherited=false)

See Also

System.Security.Permissions Namespace

Members

ReflectionPermissionAttribute Constructors

ReflectionPermissionAttribute Constructor

ReflectionPermissionAttribute Methods

ReflectionPermissionAttribute.CreatePermission Method

ReflectionPermissionAttribute Properties

ReflectionPermissionAttribute.Flags Property


ReflectionPermissionAttribute Constructor

public ReflectionPermissionAttribute(SecurityAction action);

Summary

Constructs and initializes a new instance of the ReflectionPermissionAttribute class with the specified SecurityAction value.

Parameters

action
A SecurityAction value.

Exceptions

Exception TypeCondition
ArgumentExceptionaction is not a valid SecurityAction value.

See Also

System.Security.Permissions.ReflectionPermissionAttribute Class, System.Security.Permissions Namespace

ReflectionPermissionAttribute.CreatePermission Method

public override IPermission CreatePermission();

Summary

Returns a new ReflectionPermission that contains the security information of the current instance.

Return Value

A new ReflectionPermission object with the security information of the current instance.

Description

[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.

]

See Also

System.Security.Permissions.ReflectionPermissionAttribute Class, System.Security.Permissions Namespace

ReflectionPermissionAttribute.Flags Property

public ReflectionPermissionFlag Flags { get; set; }

Summary

Gets or sets levels of access to non-public types using reflection.

Property Value

One or more of the ReflectionPermissionFlag values.

Description

[Note: To specify multiple ReflectionPermissionFlag values for a set operation, use the bitwise OR operator.]

See Also

System.Security.Permissions.ReflectionPermissionAttribute Class, System.Security.Permissions Namespace