Partager via


FirstMatchCodeGroup(IMembershipCondition, PolicyStatement) Constructeur

Définition

Initialise une nouvelle instance de la classe 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)

Paramètres

membershipCondition
IMembershipCondition

Condition d'appartenance qui teste les preuves pour déterminer si ce groupe de codes applique une stratégie.

policy
PolicyStatement

Instruction de stratégie pour le groupe de codes sous la forme d'un jeu d'autorisations et d'attributs pour attribuer du code correspondant à la condition d'appartenance.

Exceptions

Le type du paramètre membershipCondition n'est pas valide.

- ou -

Le type du paramètre policy n'est pas valide.

Exemples

Le code suivant montre l’utilisation du FirstMatchCodeGroup constructeur. Cet exemple de code fait partie d’un exemple plus grand fourni pour la FirstMatchCodeGroup classe .

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)

Remarques

Ce constructeur crée un groupe de code de base et doit être appelé à partir des constructeurs des groupes de code personnalisés. Les groupes de code enfants peuvent être ajoutés à l’aide de la AddChild méthode .

S’applique à