Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

UIPermission.Union Method

Creates a permission that is the union of the permission and the specified permission.

[Visual Basic]
Overrides Public Function Union( _
   ByVal target As IPermission _
) As IPermission Implements IPermission.Union
[C#]
public override IPermission Union(
 IPermission target
);
[C++]
public: IPermission* Union(
 IPermission* target
);
[JScript]
public override function Union(
   target : IPermission
) : IPermission;

Parameters

target
A permission to combine with the current permission. It must be the same type as the current permission.

Return Value

A new permission that represents the union of the current permission and the specified permission.

Implements

IPermission.Union

Exceptions

Exception Type Condition
ArgumentException The target parameter is not a null reference (Nothing in Visual Basic) and is not of the same type as the current permission.

Remarks

The result of a call to Union is a permission that represents all the operations represented by the current permission as well as all the operations represented by the specified permission. Specifically, it represents the most permissive values of UIPermissionWindow and UIPermissionClipboard from those in the current permission and the specified permission.

Example

[Visual Basic] 
' Union creates a new permission that is the union of the current permission and the specified permission.
Private Function UnionDemo() As Boolean
    Dim returnValue As Boolean = True
    Dim ui1, ui2 As UIPermissionWindow
    Dim cb1, cb2 As UIPermissionClipboard
    Dim uiIdPerm1, uiIdPerm2 As UIPermission
    Dim uiIdPerm3 As IPermission
    Dim uiGen1 As New UIGenerator()
    Dim uiGen2 As New UIGenerator()
    uiGen1.ResetIndex()
    While uiGen1.CreateUI(uiIdPerm1, ui1, cb1)
        If uiIdPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("**********************************************************" & ControlChars.Lf)
        uiGen2.ResetIndex()

        While uiGen2.CreateUI(uiIdPerm2, ui2, cb2)
            If uiIdPerm2 Is Nothing Then
                GoTo ContinueWhile2
            End If
            uiIdPerm3 = CType(uiIdPerm1.Union(uiIdPerm2), UIPermission)
            uiIdPerm3 = uiIdPerm1.Union(uiIdPerm2)

            If uiIdPerm3 Is Nothing Then
                Console.WriteLine(("The union of " & ui1.ToString() & " and " & ui2.ToString() & " is null."))
            Else
                Console.WriteLine(("The union of " & uiIdPerm1.Window.ToString() & " and " _
                & uiIdPerm1.Clipboard.ToString() & " with " & uiIdPerm2.Window.ToString() _
                & " and " & uiIdPerm2.Clipboard.ToString() & " = " & ControlChars.Lf _
                & ControlChars.Tab & CType(uiIdPerm3, UIPermission).Window.ToString() & " and " _
                & CType(uiIdPerm3, UIPermission).Clipboard.ToString()))
            End If
ContinueWhile2:
        End While
ContinueWhile1:
    End While


    Return returnValue
End Function 'UnionDemo


[C#] 
// Union creates a new permission that is the union of the current permission and the specified permission.
    private bool UnionDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermissionClipboard cb1, cb2;
        UIPermission uiIdPerm1,uiIdPerm2;
        IPermission uiIdPerm3;
        UIGenerator uiGen1 = new UIGenerator();
        UIGenerator uiGen2 = new UIGenerator();
        uiGen1.ResetIndex();
        while(uiGen1.CreateUI(out uiIdPerm1, out ui1, out cb1)) 
        {
            if(uiIdPerm1 == null) continue;
            Console.WriteLine("**********************************************************\n");
            uiGen2.ResetIndex();

            while(uiGen2.CreateUI(out uiIdPerm2, out ui2, out cb2)) 
            {
                if(uiIdPerm2 == null) continue;
                uiIdPerm3 = (UIPermission)uiIdPerm1.Union(uiIdPerm2);
                uiIdPerm3 = uiIdPerm1.Union(uiIdPerm2);

                if(uiIdPerm3 == null)  
                {
                    Console.WriteLine("The union of " +  ui1 + " and " + ui2 + " is null." );
                }
                else
                {
                    Console.WriteLine("The union of " + uiIdPerm1.Window + " and " + uiIdPerm1.Clipboard + " with " + 
                        uiIdPerm2.Window + " and " + uiIdPerm2.Clipboard + " = \n\t" + 
                        ((UIPermission)uiIdPerm3).Window.ToString() + " and " + ((UIPermission)uiIdPerm3).Clipboard.ToString());
                }

            }
        }

        return returnValue;

    }

[C++] 
// Union creates a new permission that is the union of the current permission and the specified permission.
private:
bool UnionDemo()
{
    bool returnValue = true;
    UIPermissionWindow ui1,ui2;
    UIPermissionClipboard cb1, cb2;
    UIPermission* uiIdPerm1;
    UIPermission* uiIdPerm2;
    IPermission* uiIdPerm3;
    UIGenerator* uiGen1 = new UIGenerator();
    UIGenerator* uiGen2 = new UIGenerator();
    uiGen1->ResetIndex();
    while(uiGen1->CreateUI(&uiIdPerm1, &ui1, &cb1)) 
    {
        if(uiIdPerm1 == 0) continue;
        Console::WriteLine(S"**********************************************************\n");
        uiGen2->ResetIndex();

        while(uiGen2->CreateUI(&uiIdPerm2, &ui2, &cb2)) 
        {
            if(uiIdPerm2 == 0) continue;
            uiIdPerm3 = dynamic_cast<UIPermission*>(uiIdPerm1->Union(uiIdPerm2));
            uiIdPerm3 = uiIdPerm1->Union(uiIdPerm2);

            if(uiIdPerm3 == 0)  
            {
                Console::WriteLine(S"The union of {0} and {1} is null.",
                    __box(ui1), __box(ui2));
            }
            else
            {
                Console::WriteLine(S"The union of {0} and {1} with {2} and {3} = \n\t{4} and {5}",
                    __box(uiIdPerm1->Window), __box(uiIdPerm1->Clipboard),
                    __box(uiIdPerm2->Window), __box(uiIdPerm2->Clipboard),
                    __box((dynamic_cast<UIPermission*>(uiIdPerm3))->Window)->ToString(),
                    __box((dynamic_cast<UIPermission*>(uiIdPerm3))->Clipboard)->ToString());
            }

        }
    }

    return returnValue;

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

UIPermission Class | UIPermission Members | System.Security.Permissions Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.