Compartir a través de


FirstMatchCodeGroup(IMembershipCondition, PolicyStatement) Constructor

Definición

Inicializa una nueva instancia de la clase FirstMatchCodeGroup.

public:
 FirstMatchCodeGroup(System::Security::Policy::IMembershipCondition ^ membershipCondition, System::Security::Policy::PolicyStatement ^ policy);
public FirstMatchCodeGroup (System.Security.Policy.IMembershipCondition membershipCondition, System.Security.Policy.PolicyStatement policy);
new System.Security.Policy.FirstMatchCodeGroup : System.Security.Policy.IMembershipCondition * System.Security.Policy.PolicyStatement -> System.Security.Policy.FirstMatchCodeGroup
Public Sub New (membershipCondition As IMembershipCondition, policy As PolicyStatement)

Parámetros

membershipCondition
IMembershipCondition

Condición de pertenencia que comprueba la evidencia para determinar si este grupo de código aplica la directiva.

policy
PolicyStatement

Instrucción de directiva del grupo de código en forma de conjunto de permisos y atributos que se conceden al código que cumple la condición de pertenencia.

Excepciones

El tipo del parámetro membershipCondition no es válido.

o bien

El tipo del parámetro policy no es válido.

Ejemplos

En el código siguiente se muestra el uso del FirstMatchCodeGroup constructor . Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la FirstMatchCodeGroup clase .

FileIOPermission^ rootFilePermissions =
   gcnew FileIOPermission( PermissionState::None );
rootFilePermissions->AllLocalFiles = FileIOPermissionAccess::Read;
rootFilePermissions->SetPathList( FileIOPermissionAccess::Read, L"C:\\" );

// Add a permission to a named permission set.
NamedPermissionSet^ namedPermissions =
   gcnew NamedPermissionSet( L"RootPermissions" );
namedPermissions->AddPermission( rootFilePermissions );

// Create a PolicyStatement with exclusive rights to the policy.
PolicyStatement^ policy = gcnew PolicyStatement(
   namedPermissions,PolicyStatementAttribute::Exclusive );

// Create a FirstMatchCodeGroup with a membership condition that
// matches all code, and an exclusive policy.
FirstMatchCodeGroup^ codeGroup = gcnew FirstMatchCodeGroup(
   gcnew AllMembershipCondition,policy );
FileIOPermission rootFilePermissions =
    new FileIOPermission(PermissionState.None);
rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read;
rootFilePermissions.SetPathList(FileIOPermissionAccess.Read,"C:\\");

// Add a permission to a named permission set.
NamedPermissionSet namedPermissions =
    new NamedPermissionSet("RootPermissions");
namedPermissions.AddPermission(rootFilePermissions);

// Create a PolicyStatement with exclusive rights to the policy.
PolicyStatement policy = new PolicyStatement(
    namedPermissions,PolicyStatementAttribute.Exclusive);

// Create a FirstMatchCodeGroup with a membership condition that
// matches all code, and an exclusive policy.
FirstMatchCodeGroup codeGroup =
    new FirstMatchCodeGroup(
    new AllMembershipCondition(),
    policy);
Dim rootFilePermissions As New FileIOPermission(PermissionState.None)
rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read
rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\")

' Add a permission to a named permission set.
Dim namedPermissions As New NamedPermissionSet("RootPermissions")
namedPermissions.AddPermission(rootFilePermissions)

' Create a PolicyStatement with exclusive rights to the policy.
Dim policy As New PolicyStatement( _
    namedPermissions, _
    PolicyStatementAttribute.Exclusive)

' Create a FirstMatchCodeGroup with a membership condition that 
' matches all code, and an exclusive policy.
Dim codeGroup As New FirstMatchCodeGroup( _
    New AllMembershipCondition, _
    policy)

Comentarios

Este constructor crea un grupo de código básico y se debe llamar desde los constructores de grupos de código personalizados. Los grupos de código secundarios se pueden agregar mediante el AddChild método .

Se aplica a