This documentation is archived and is not being maintained.

FirstMatchCodeGroup Constructor

Initializes a new instance of the FirstMatchCodeGroup class.

Namespace: System.Security.Policy
Assembly: mscorlib (in mscorlib.dll)

public FirstMatchCodeGroup (
	IMembershipCondition membershipCondition,
	PolicyStatement policy
)
public FirstMatchCodeGroup (
	IMembershipCondition membershipCondition, 
	PolicyStatement policy
)
public function FirstMatchCodeGroup (
	membershipCondition : IMembershipCondition, 
	policy : PolicyStatement
)

Parameters

membershipCondition

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

policy

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

Exception typeCondition

ArgumentException

The type of the membershipCondition parameter is not valid.

-or-

The type of the policy parameter is not valid.

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.

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 =
    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);

FileIOPermission rootFilePermissions = new FileIOPermission(
    PermissionState.None);
rootFilePermissions.set_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);

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: