TypeBuilder.AddDeclarativeSecurity Method (SecurityAction, PermissionSet)

 

Adds declarative security to this type.

Namespace:   System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

member AddDeclarativeSecurity : 
        action:SecurityAction *
        pset:PermissionSet -> unit

Parameters

action
Type: System.Security.Permissions.SecurityAction

The security action to be taken such as Demand, Assert, and so on.

pset
Type: System.Security.PermissionSet

The set of permissions the action applies to.

Exception Condition
ArgumentOutOfRangeException

The action is invalid (RequestMinimum, RequestOptional, and RequestRefuse are invalid).

InvalidOperationException

The containing type has been created using CreateType.

-or-

The permission set pset contains an action that was added earlier by AddDeclarativeSecurity.

ArgumentNullException

pset is null.

AddDeclarativeSecurity may be called several times with each call specifying a security action (such as Demand, Assert, or Deny) and a set of permissions that apply to the action.

System_CAPS_noteNote

In the .NET Framework versions 1.0, 1.1, and 2.0, the declarative security attributes applied to a type by using this method are stored in the old XML metadata format.

The following example demonstrates the use of the AddDeclarativeSecurity method to add a security demand for SecurityPermission with the SecurityPermissionFlag.ControlEvidence flag to a dynamic type named MyDynamicClass, in an assembly named EmittedExample.dll. The example produces no console output; after you run it, you can use Ildasm.exe (IL Disassembler) to examine EmittedExample.dll. In MyDynamicClass, open the .class public auto ansi statement to see the declarative permission.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: