UIPermission.Union(IPermission) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立權限與指定權限聯集的權限。
public:
override System::Security::IPermission ^ Union(System::Security::IPermission ^ target);
public override System.Security.IPermission Union (System.Security.IPermission target);
override this.Union : System.Security.IPermission -> System.Security.IPermission
Public Overrides Function Union (target As IPermission) As IPermission
參數
- target
- IPermission
要與目前權限結合的權限, 必須與目前權限屬於相同的類型。
傳回
代表目前權限與指定權限聯集的新權限。
例外狀況
target
參數不是 null
,而且與目前權限屬於不同的類型。
範例
下列程式碼範例顯示 方法的行為 Union 。 這個範例是提供給 類別之較大範例的 UIPermission 一部分。
注意
程式碼範例旨在顯示 方法的行為,而不是示範其用法。 一般而言,安全性基礎結構會使用許可權類別的方法;它們通常不會用於應用程式。
// Union creates a new permission that is the union of the current permission
// and the specified permission.
void UnionDemo()
{
Console::WriteLine("\n************************ Union() Demo *************************\n");
UIPermission ^ uiPerm1 = gcnew UIPermission(UIPermissionWindow::SafeTopLevelWindows);
UIPermission ^ uiPerm2 = gcnew UIPermission(UIPermissionWindow::SafeSubWindows);
UIPermission ^ p3 = dynamic_cast<UIPermission^>(uiPerm1->Union(uiPerm2));
Console::WriteLine(" The union of {0} and \n\t{1} = {2} ", uiPerm1->Window,
uiPerm2->Window, (nullptr != p3)?p3->Window.ToString():"null");
}
// Union creates a new permission that is the union of the current permission
// and the specified permission.
private static void UnionDemo()
{
UIPermission uiPerm1 = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);
UIPermission uiPerm2 = new UIPermission(UIPermissionWindow.SafeSubWindows);
UIPermission p3 = (UIPermission)uiPerm1.Union(uiPerm2);
if (p3 != null)
{
Console.WriteLine("The union of " + uiPerm1.Window.ToString() +
" and \n\t" + uiPerm2.Window.ToString() + " is \n\t"
+ p3.Window.ToString() + "\n");
}
else
{
Console.WriteLine("The union of " + uiPerm1.Window.ToString() +
" and \n\t" + uiPerm2.Window.ToString() + " is null.\n");
}
}
' Union creates a new permission that is the union of the current permission
' and the specified permission.
Private Shared Sub UnionDemo()
Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows)
Dim uiPerm2 As New UIPermission(UIPermissionWindow.SafeSubWindows)
Dim p3 As UIPermission = CType(uiPerm1.Union(uiPerm2), UIPermission)
If Not (p3 Is Nothing) Then
Console.WriteLine("The union of " + uiPerm1.Window.ToString() + " and " + vbLf + vbTab + uiPerm2.Window.ToString() + " is " + vbLf + vbTab + p3.Window.ToString() + vbLf)
Else
Console.WriteLine("The union of " + uiPerm1.Window.ToString() + " and " + vbLf + vbTab + uiPerm2.Window.ToString() + " is null." + vbLf)
End If
End Sub
備註
呼叫 Union 的結果是許可權,代表目前許可權所代表的所有作業,以及指定許可權所代表的所有作業。 具體來說,它代表目前許可權和指定許可權中最寬鬆的 和 UIPermissionClipboard 值 UIPermissionWindow 。