แก้ไข

แชร์ผ่าน


FirstMatchCodeGroup(IMembershipCondition, PolicyStatement) Constructor

Definition

Initializes a new instance of the FirstMatchCodeGroup class.

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)

Parameters

membershipCondition
IMembershipCondition

A membership condition that tests evidence to determine whether this code group applies policy.

policy
PolicyStatement

The policy statement for the code group in the form of a permission set and attributes to grant code that matches the membership condition.

Exceptions

The type of the membershipCondition parameter is not valid.

-or-

The type of the policy parameter is not valid.

Examples

The following code shows the use of the FirstMatchCodeGroup constructor. This code example is part of a larger example provided for FirstMatchCodeGroup class.

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)

Remarks

This constructor creates a basic code group and should be called from the constructors of custom code groups. Child code groups can be added using the AddChild method.

Applies to