UIPermission.Union(IPermission) Metoda

Definicja

Tworzy uprawnienie, które jest unią uprawnienia i określonego uprawnienia.

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

Parametry

target
IPermission

Uprawnienie do łączenia z bieżącym uprawnieniem. Musi to być ten sam typ co bieżące uprawnienie.

Zwraca

IPermission

Nowe uprawnienie reprezentujące związek bieżącego uprawnienia i określone uprawnienie.

Wyjątki

Parametr target nie null jest i nie jest tego samego typu co bieżące uprawnienie.

Przykłady

Poniższy przykład kodu przedstawia zachowanie Union metody . Ten przykład jest częścią większego przykładu udostępnionego UIPermission dla klasy .

Uwaga

Przykładowy kod jest przeznaczony do pokazania zachowania metody, a nie do zademonstrowania jej użycia. Ogólnie rzecz biorąc, metody klas uprawnień są używane przez infrastrukturę zabezpieczeń; nie są one zwykle używane w aplikacjach.

   // 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

Uwagi

Wynikiem wywołania metody Union jest uprawnienie, które reprezentuje wszystkie operacje reprezentowane przez bieżące uprawnienie, a także wszystkie operacje reprezentowane przez określone uprawnienie. W szczególności reprezentuje najbardziej permissywne wartości UIPermissionWindow i UIPermissionClipboard z tych w bieżącym uprawnieniem i określonym uprawnieniem.

Dotyczy