StrongNameIdentityPermission.Union Method (IPermission)

 

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

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

public override IPermission Union(
	IPermission target
)

Parameters

target
Type: System.Security.IPermission

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

Return Value

Type: System.Security.IPermission

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

Exception Condition
ArgumentException

The target parameter is not null and is not of the same type as the current permission.

-or-

The two permissions are not equal and one is a subset of the other.

The result of a call to Union is a permission that represents all the operations represented by both the current permission and the specified permission. Any demand that passes either permission passes their union.

The union of a permission and null is the permission that is not null. The union of a permission and a subset of that permission is the permission that contains the other. Any other combination results in an ArgumentException exception being thrown.

The following code example shows the results of the use of the Union method, not how to use the method. This example is part of a larger example provided for the StrongNameIdentityPermission class. The best use for this example is to build and execute the entire example, and view its output.

System_CAPS_noteNote

The code example is intended to show the behavior of the method, not to demonstrate its use. In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications.

// Union creates a new permission that is the union of the current permission and the specified permission.
private bool UnionDemo()
{

    bool returnValue = true;

    StrongNameIdentityPermission snIdPerm1, snIdPerm2;
    IPermission snIdPerm3;

    snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
    snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", new Version("1.0.0.0"));

    snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Union(snIdPerm2);

    try
    {
        Console.WriteLine("The union of MyCompany.MyDepartment.*" +
        "and MyCompany.MyDepartment.MyFile is " +
        ((StrongNameIdentityPermission)snIdPerm3).Name.ToString());
    }
    catch (Exception e)
    {
        Console.WriteLine("An expected exception was thrown: " + e.Message);
    }


    return returnValue;

}

.NET Framework
Available since 1.1
Return to top
Show: