IPermission.Intersect(IPermission) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建并返回一个权限,该权限是当前权限与指定权限的交集。
public:
System::Security::IPermission ^ Intersect(System::Security::IPermission ^ target);
public System.Security.IPermission? Intersect (System.Security.IPermission? target);
public System.Security.IPermission Intersect (System.Security.IPermission target);
abstract member Intersect : System.Security.IPermission -> System.Security.IPermission
Public Function Intersect (target As IPermission) As IPermission
参数
- target
- IPermission
要与当前权限相交的权限。 它必须与当前权限属于同一类型。
返回
表示当前权限和指定权限的交集的一个新权限。 如果交集为空,则此新权限为 null
。
例外
target
参数不为 null
,并且是与当前权限不属于同一类的实例。
示例
下面的代码示例演示如何实现 Intersect 方法。 此代码示例是为 IPermission 类提供的一个更大示例的一部分。
// Return a new object that contains the intersection
// of 'this' and 'target'.
public:
virtual IPermission^ Intersect(IPermission^ target) override
{
// If 'target' is null, return null.
if (target == nullptr)
{
return nullptr;
}
// Both objects must be the same type.
SoundPermission^ soundPerm = VerifyTypeMatch(target);
// If 'this' and 'target' are unrestricted,
// return a new unrestricted permission.
if (specifiedAsUnrestricted && soundPerm->specifiedAsUnrestricted)
{
return Clone(true, SoundPermissionState::PlayAnySound);
}
// Calculate the intersected permissions.
// If there are none, return null.
SoundPermissionState minimumPermission = (SoundPermissionState)
Math::Min((int) stateFlags, (int) soundPerm->stateFlags);
if ((int)minimumPermission == 0)
{
return nullptr;
}
// Return a new object with the intersected permission value.
return Clone(false, minimumPermission);
}
// Return a new object that contains the intersection of 'this' and 'target'.
public override IPermission Intersect(IPermission target)
{
// If 'target' is null, return null.
if (target == null) return null;
// Both objects must be the same type.
SoundPermission soundPerm = VerifyTypeMatch(target);
// If 'this' and 'target' are unrestricted, return a new unrestricted permission.
if (m_specifiedAsUnrestricted && soundPerm.m_specifiedAsUnrestricted)
return Clone(true, SoundPermissionState.PlayAnySound);
// Calculate the intersected permissions. If there are none, return null.
SoundPermissionState val = (SoundPermissionState)
Math.Min((Int32)m_flags, (Int32)soundPerm.m_flags);
if (val == 0) return null;
// Return a new object with the intersected permission value.
return Clone(false, val);
}
' Return a new object that contains the intersection of 'this' and 'target'.
Public Overrides Function Intersect(ByVal target As IPermission) As IPermission
' If 'target' is null, return null.
If target Is Nothing Then
Return Nothing
End If
' Both objects must be the same type.
Dim soundPerm As SoundPermission = VerifyTypeMatch(target)
' If 'this' and 'target' are unrestricted, return a new unrestricted permission.
If m_specifiedAsUnrestricted AndAlso soundPerm.m_specifiedAsUnrestricted Then
Return Clone(True, SoundPermissionState.PlayAnySound)
End If
' Calculate the intersected permissions. If there are none, return null.
Dim val As SoundPermissionState = CType(Math.Min(CType(m_flags, Int32), CType(soundPerm.m_flags, Int32)), SoundPermissionState)
If val = 0 Then
Return Nothing
End If
' Return a new object with the intersected permission value.
Return Clone(False, val)
End Function 'Intersect
注解
两个权限的交集是描述它们共同描述的操作集的权限。 只有传递两个原始权限的要求才会通过交集。
对于 方法的所有实现 Intersect ,以下语句必须为 true。
X
和 Y
表示 IPermission 不是 null
的对象引用。
X
.相交 (X
) 返回等于X
的值。X
.相交 (Y
) 返回与 相同的值Y
。 (X
) 相交。X
.相交 (null
) 返回null
。