Compartilhar via


FirstMatchCodeGroup(IMembershipCondition, PolicyStatement) Construtor

Definição

Inicializa uma nova instância da 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)

Parâmetros

membershipCondition
IMembershipCondition

Uma condição de associação que testa a evidência para determinar se este grupo de códigos aplica a política.

policy
PolicyStatement

A declaração de política para o grupo de códigos na forma de um conjunto de permissões e atributos a serem concedidos a código que corresponda à condição de associação.

Exceções

O tipo do parâmetro membershipCondition não é válido.

- ou -

O tipo do parâmetro policy não é válido.

Exemplos

O código a seguir mostra o uso do FirstMatchCodeGroup construtor. Este exemplo de código faz parte de um exemplo maior fornecido para a 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)

Comentários

Esse construtor cria um grupo de códigos básico e deve ser chamado dos construtores de grupos de códigos personalizados. Grupos de código filho podem ser adicionados usando o AddChild método .

Aplica-se a