MethodBuilder.AddDeclarativeSecurity(SecurityAction, PermissionSet) Metoda

Definice

Přidá do této metody deklarativní zabezpečení.

public:
 void AddDeclarativeSecurity(System::Security::Permissions::SecurityAction action, System::Security::PermissionSet ^ pset);
public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction action, System.Security.PermissionSet pset);
member this.AddDeclarativeSecurity : System.Security.Permissions.SecurityAction * System.Security.PermissionSet -> unit
Public Sub AddDeclarativeSecurity (action As SecurityAction, pset As PermissionSet)

Parametry

action
SecurityAction

Akce zabezpečení, která se má provést (poptávka, assert atd.)

pset
PermissionSet

Sada oprávnění, na která se akce vztahuje.

Výjimky

Je action neplatný (RequestMinimumRequestOptionala RequestRefuse jsou neplatné).

Obsahující typ byl vytvořen pomocí CreateType().

nebo

Sada oprávnění pset obsahuje akci, která byla přidána dříve AddDeclarativeSecurity(SecurityAction, PermissionSet).

nebo

Pro aktuální metodu IsGenericMethod je truevlastnost , ale IsGenericMethodDefinition vlastnost je false.

pset je null.

Příklady

Následující ukázka kódu znázorňuje kontextové použití AddDeclarativeSecurity , které vyžaduje volající metody, aby měl neomezená oprávnění.

// myModBuilder is an instance of ModuleBuilder.

TypeBuilder myTypeBuilder = myModBuilder.DefineType("MyType",
                    TypeAttributes.Public);

MethodBuilder myMethod1 = myTypeBuilder.DefineMethod("MyMethod",
                    MethodAttributes.Public,
                    typeof(int),
                    new Type[]
                    {typeof(int), typeof(int)});	

PermissionSet myMethodPermissions = new PermissionSet(
            PermissionState.Unrestricted);

myMethod1.AddDeclarativeSecurity(SecurityAction.Demand,
                 myMethodPermissions);
' myModBuilder is an instance of ModuleBuilder.
' Note that for the use of PermissionSet and SecurityAction,
' the namespaces System.Security and System.Security.Permissions
' should be included.
Dim myTypeBuilder As TypeBuilder = myModBuilder.DefineType("MyType", _
                        TypeAttributes.Public)

Dim myMethod1 As MethodBuilder = myTypeBuilder.DefineMethod("MyMethod", _
                       MethodAttributes.Public, _
                       GetType(Integer), _
                       New Type() {GetType(Integer), GetType(Integer)})

Dim myMethodPermissions As New PermissionSet(PermissionState.Unrestricted)

myMethod1.AddDeclarativeSecurity(SecurityAction.Demand, myMethodPermissions)

Poznámky

AddDeclarativeSecuritylze volat několikrát, přičemž každé volání určuje akci zabezpečení (například DemandAssert, a Deny) a sadu oprávnění, na které se akce vztahuje.

Note

V rozhraní .NET Framework verze 1.0, 1.1 a 2.0 jsou deklarativní atributy zabezpečení použité na metodu pomocí metody AddDeclarativeSecurity uloženy ve starém formátu metadat XML. Viz Generování deklarativních atributů zabezpečení.

Platí pro