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
的物件。