StrongNameIdentityPermission::Union Method (IPermission^)
Creates a permission that is the union of the current permission and the specified permission.
Assembly: mscorlib (in mscorlib.dll)
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.
Implements
IPermission::Union(IPermission^)| 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.
Note |
|---|
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. bool UnionDemo() { bool returnValue = true; StrongNameIdentityPermission^ snIdPerm1; StrongNameIdentityPermission^ snIdPerm2; IPermission^ snIdPerm3; snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", gcnew Version("1.0.0.0")); snIdPerm2 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", gcnew Version("1.0.0.0")); snIdPerm3 = dynamic_cast<StrongNameIdentityPermission^>(snIdPerm1->Union( snIdPerm2 )); snIdPerm3 = snIdPerm1->Union( snIdPerm2 ); try { Console::WriteLine("The union of MyCompany.MyDepartment.*" + "and MyCompany.MyDepartment.MyFile is " + (dynamic_cast<StrongNameIdentityPermission^>(snIdPerm3))->Name); } catch (Exception^ e) { Console::WriteLine("An expected exception was thrown: " + e->Message); } return returnValue; }
Available since 1.1
