This documentation is archived and is not being maintained.

UIPermission.Union Method

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

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

public override IPermission Union (
	IPermission target
)
public IPermission Union (
	IPermission target
)
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.

Exception typeCondition

ArgumentException

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

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.

For the complete example, see the UIPermission class topic.

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 ui1, out cb1))
    {
        uiIdPerm1 = new UIPermission(ui1, cb1);
        Console.WriteLine("**********************************************************\n");
        uiGen2.ResetIndex();

        while (uiGen2.CreateUI(out ui2, out cb2))
        {
            uiIdPerm2 = new UIPermission(ui2, cb2);
            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;

}

// Union creates a new permission that is the union of the current 
// permission and the specified permission.
private boolean UnionDemo()
{
    boolean returnValue = true;
    UIPermissionWindow ui1[] = new UIPermissionWindow[1];
    UIPermissionWindow ui2[] = new UIPermissionWindow[1];
    UIPermissionClipboard cb1[] = new UIPermissionClipboard[1];
    UIPermissionClipboard cb2[] = new UIPermissionClipboard[1];
    UIPermission uiIdPerm1[] = new UIPermission[1];
    UIPermission uiIdPerm2[] = new UIPermission[1];
    IPermission uiIdPerm3;
    UIGenerator uiGen1 = new UIGenerator();
    UIGenerator uiGen2 = new UIGenerator();

    uiGen1.ResetIndex();
    while (uiGen1.CreateUI(uiIdPerm1, ui1, cb1)) {
        if (uiIdPerm1[0] == null) {
            continue;
        }
        Console.WriteLine("*************************************" 
            + "*********************\n");
        uiGen2.ResetIndex();
        while (uiGen2.CreateUI(uiIdPerm2, ui2, cb2)) {
            if (uiIdPerm2[0] == null) {
                continue;
            }
            uiIdPerm3 = ((UIPermission)(uiIdPerm1[0].Union(uiIdPerm2[0])));
            uiIdPerm3 = uiIdPerm1[0].Union(uiIdPerm2[0]);
            if (uiIdPerm3 == null) {
                Console.WriteLine(("The union of " + ui1[0] + " and " 
                    + ui2[0] + " is null."));
            }
            else {
                Console.WriteLine(("The union of " 
                    + uiIdPerm1[0].get_Window() + " and " 
                    + uiIdPerm1[0].get_Clipboard() + " with " 
                    + uiIdPerm2[0].get_Window() + " and " 
                    + uiIdPerm2[0].get_Clipboard() + " = \n\t" 
                    + ((UIPermission)(uiIdPerm3)).get_Window().ToString() 
                    + " and " + ((UIPermission)(uiIdPerm3)).get_Clipboard().
                    ToString()));
            }
        }
    }
    return returnValue;
} //UnionDemo

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: