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
回 。