FirstMatchCodeGroup(IMembershipCondition, PolicyStatement) 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 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)
参数
- membershipCondition
- IMembershipCondition
成员条件,它测试证据以确定此代码组是否应用策略。
- policy
- PolicyStatement
形式为权限集和特性的代码组的策略声明,这些权限集和特性将被授予匹配成员条件的代码。
例外
示例
以下代码演示了构造函数的 FirstMatchCodeGroup 用法。 此代码示例是为 FirstMatchCodeGroup 类提供的更大示例的一部分。
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)
注解
此构造函数创建基本代码组,应从自定义代码组的构造函数调用。 可以使用 方法添加 AddChild 子代码组。