Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Fügt dieser Methode Deklarationssicherheit hinzu.
Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub AddDeclarativeSecurity ( _
action As SecurityAction, _
pset As PermissionSet _
)
'Usage
Dim instance As MethodBuilder
Dim action As SecurityAction
Dim pset As PermissionSet
instance.AddDeclarativeSecurity(action, pset)
public void AddDeclarativeSecurity (
SecurityAction action,
PermissionSet pset
)
public:
void AddDeclarativeSecurity (
SecurityAction action,
PermissionSet^ pset
)
public void AddDeclarativeSecurity (
SecurityAction action,
PermissionSet pset
)
public function AddDeclarativeSecurity (
action : SecurityAction,
pset : PermissionSet
)
Parameter
- action
Die auszuführende Sicherheitsaktion (Demand, Assert usw.).
- pset
Der Berechtigungssatz, auf den die Aktion angewendet wird.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
Die action ist ungültig (RequestMinimum, RequestOptional und RequestRefuse sind ungültig). |
|
Der enthaltende Typ wurde mit CreateType erstellt. – oder – Der Berechtigungssatz pset enthält eine Aktion, die bereits durch AddDeclarativeSecurity hinzugefügt wurde. – oder – Für die aktuelle Methode ist die IsGenericMethod-Eigenschaft true, die IsGenericMethodDefinition-Eigenschaft ist jedoch false. |
|
pset ist NULL (Nothing in Visual Basic). |
Beispiel
Das folgende Codebeispiel veranschaulicht die kontextabhängige Verwendung von AddDeclarativeSecurity, um es erforderlich zu machen, dass Aufrufer einer Methode über uneingeschränkte Berechtigungen verfügen müssen.
' 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)
// 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.
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.
TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "MyType",
TypeAttributes::Public );
array<Type^>^ temp0 = {int::typeid, int::typeid};
MethodBuilder^ myMethod1 = myTypeBuilder->DefineMethod( "MyMethod",
MethodAttributes::Public,
int::typeid, temp0 );
PermissionSet^ myMethodPermissions = gcnew 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.
TypeBuilder myTypeBuilder = myModBuilder.DefineType("MyType",
TypeAttributes.Public);
MethodBuilder myMethod1 = myTypeBuilder.DefineMethod("MyMethod",
MethodAttributes.Public,int.class.ToType(),
new Type[] { int.class.ToType(), int.class.ToType() });
PermissionSet myMethodPermissions =
new PermissionSet(PermissionState.Unrestricted);
myMethod1.AddDeclarativeSecurity(SecurityAction.Demand,
myMethodPermissions);
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
MethodBuilder-Klasse
MethodBuilder-Member
System.Reflection.Emit-Namespace