IPermission.Union(IPermission) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建一个权限,该权限是当前权限与指定权限的并集。
public:
System::Security::IPermission ^ Union(System::Security::IPermission ^ target);
public System.Security.IPermission? Union (System.Security.IPermission? target);
public System.Security.IPermission Union (System.Security.IPermission target);
abstract member Union : System.Security.IPermission -> System.Security.IPermission
Public Function Union (target As IPermission) As IPermission
参数
- target
- IPermission
与当前权限合并的权限。 它必须与当前权限属于同一类型。
返回
表示同时兼具当前权限和指定权限的新权限。
例外
target
参数不为 null
,并且与当前权限不属于同一类型。
示例
下面的代码示例演示如何实现 Union 方法。 此代码示例是为 IPermission 类提供的一个更大示例的一部分。
// Return a new object that contains the union of 'this' and 'target'.
// Note: You do not have to implement this method.
// If you do not, the version
// in CodeAccessPermission does this:
// 1. If target is not null, a NotSupportedException is thrown.
// 2. If target is null, then Copy is called and
// the new object is returned.
public:
virtual IPermission^ Union(IPermission^ target) override
{
// If 'target' is null, then return a copy of 'this'.
if (target == nullptr)
{
return Copy();
}
// Both objects must be the same type.
SoundPermission^ soundPerm = VerifyTypeMatch(target);
// If 'this' or 'target' are unrestricted,
// return a new unrestricted permission.
if (specifiedAsUnrestricted || soundPerm->specifiedAsUnrestricted)
{
return Clone(true, SoundPermissionState::PlayAnySound);
}
// Return a new object with the calculated, unioned permission value.
return Clone(false, (SoundPermissionState)
Math::Max((int) stateFlags, (int) soundPerm->stateFlags));
}
// Return a new object that contains the union of 'this' and 'target'.
// Note: You do not have to implement this method. If you do not, the version
// in CodeAccessPermission does this:
// 1. If target is not null, a NotSupportedException is thrown.
// 2. If target is null, then Copy is called and the new object is returned.
public override IPermission Union(IPermission target)
{
// If 'target' is null, then return a copy of 'this'.
if (target == null) return Copy();
// Both objects must be the same type.
SoundPermission soundPerm = VerifyTypeMatch(target);
// If 'this' or 'target' are unrestricted, return a new unrestricted permission.
if (m_specifiedAsUnrestricted || soundPerm.m_specifiedAsUnrestricted)
return Clone(true, SoundPermissionState.PlayAnySound);
// Return a new object with the calculated, unioned permission value.
return Clone(false, (SoundPermissionState)
Math.Max((Int32)m_flags, (Int32)soundPerm.m_flags));
}
' Return a new object that contains the union of 'this' and 'target'.
' Note: You do not have to implement this method. If you do not, the version
' in CodeAccessPermission does this:
' 1. If target is not null, a NotSupportedException is thrown.
' 2. If target is null, then Copy is called and the new object is returned.
Public Overrides Function Union(ByVal target As IPermission) As IPermission
' If 'target' is null, then return a copy of 'this'.
If target Is Nothing Then
Return Copy()
End If
' Both objects must be the same type.
Dim soundPerm As SoundPermission = VerifyTypeMatch(target)
' If 'this' or 'target' are unrestricted, return a new unrestricted permission.
If m_specifiedAsUnrestricted OrElse soundPerm.m_specifiedAsUnrestricted Then
Return Clone(True, SoundPermissionState.PlayAnySound)
End If
' Return a new object with the calculated, unioned permission value.
Return Clone(False, CType(Math.Max(CType(m_flags, Int32), CType(soundPerm.m_flags, Int32)), SoundPermissionState))
End Function 'Union
注解
调用 Union 的结果是权限,该权限表示当前权限和指定权限表示的所有操作。 通过任一权限的任何要求都会通过其联合。
对于 方法的所有实现 Union ,以下语句必须为 true。
X
和 Y
表示 IPermission 不是 null
的对象。
X
.联合 (X
) 返回与 具有相同值X
的对象。X
.联合 (Y
) 返回与 返回Y
的对象具有相同值的对象。联合 (X
) 。X
.联合 (null
) 返回与 具有相同值X
的对象。