RegistryPermission.Union Method
Creates a permission that is the union of the current permission and the specified permission.
[Visual Basic] Overrides Public Function Union( _ ByVal other As IPermission _ ) As IPermission Implements IPermission.Union [C#] public override IPermission Union( IPermission other ); [C++] public: IPermission* Union( IPermission* other ); [JScript] public override function Union( other : IPermission ) : IPermission;
Parameters
- other
- A permission to combine with the current permission. It must be of 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
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentException | The other 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 both the current permission and the specified permission. Any demand that passes either permission passes their union.
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 reg1, reg2 As String Dim regPerm1, regPerm2 As RegistryPermission Dim regIdPerm3 As IPermission Dim regGen1 As New regGenerator() Dim regGen2 As New regGenerator() regGen1.ResetIndex() While regGen1.CreateReg(regPerm1, reg1, RegistryPermissionAccess.Read) If reg1 Is Nothing Then GoTo ContinueWhile1 End If Console.WriteLine("**********************************************************" & ControlChars.Lf) regGen2.ResetIndex() While regGen2.CreateReg(regPerm2, reg2, RegistryPermissionAccess.Read) Try If regPerm2 Is Nothing Then GoTo ContinueWhile2 End If Dim firstPermission As String = IIf(reg1 = "" Or reg1 Is Nothing, "null", reg1) Dim secondPermission As String = IIf(reg2 = "" Or reg2 Is Nothing, "null", reg2) regIdPerm3 = CType(regPerm1.Union(regPerm2), RegistryPermission) regIdPerm3 = regPerm1.Union(regPerm2) If regIdPerm3 Is Nothing Then Console.WriteLine(("The union of " & firstPermission & " and " & ControlChars.Lf & ControlChars.Tab & secondPermission & " is null.")) Else Console.WriteLine(("The union of " & firstPermission & " and " & ControlChars.Lf & ControlChars.Tab & secondPermission & " = " & ControlChars.Lf & ControlChars.Tab & CType(regIdPerm3, RegistryPermission).GetPathList(RegistryPermissionAccess.Read).ToString())) End If Catch e As Exception Console.WriteLine(("An exception was thrown for union :" & e.ToString())) returnValue = False End Try 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; string reg1,reg2; RegistryPermission regPerm1,regPerm2; IPermission regIdPerm3; RegGenerator regGen1 = new RegGenerator(); RegGenerator regGen2 = new RegGenerator(); regGen1.ResetIndex(); while(regGen1.CreateReg(out regPerm1, out reg1, RegistryPermissionAccess.Read)) { if(reg1 == null) continue; Console.WriteLine("**********************************************************\n"); regGen2.ResetIndex(); while(regGen2.CreateReg(out regPerm2, out reg2, RegistryPermissionAccess.Read)) { try { if(regPerm2 == null) continue; string firstPermission = reg1 == "" | reg1 == null ? "null" : reg1 ; string secondPermission = reg2 == "" | reg2 == null ? "null" : reg2; regIdPerm3 = (RegistryPermission)regPerm1.Union(regPerm2); regIdPerm3 = regPerm1.Union(regPerm2); if(regIdPerm3 == null) { Console.WriteLine("The union of " + firstPermission + " and \n\t" + secondPermission + " is null."); } else { Console.WriteLine("The union of " + firstPermission + " and \n\t" + secondPermission + " = \n\t" + ((RegistryPermission)regIdPerm3).GetPathList(RegistryPermissionAccess.Read).ToString()); } } catch(Exception e) { Console.WriteLine("An exception was thrown for union :" + e); returnValue=false; } } } return returnValue; } [C++] // Union creates a new permission that is the union of the current permission and // the specified permission. bool UnionDemo() { bool returnValue = true; String* reg1; String* reg2; RegistryPermission* regPerm1; RegistryPermission* regPerm2; IPermission* regIdPerm3; RegGenerator* regGen1 = new RegGenerator(); RegGenerator* regGen2 = new RegGenerator(); regGen1->ResetIndex(); while(regGen1->CreateReg(®Perm1, ®1, RegistryPermissionAccess::Read)) { if(reg1 == 0) continue; Console::WriteLine(S"**********************************************************\n"); regGen2->ResetIndex(); while(regGen2->CreateReg(®Perm2, ®2, RegistryPermissionAccess::Read)) { try { if(regPerm2 == 0) continue; String* firstPermission = reg1->Equals(S"") || reg1 == 0 ? S"null" : reg1 ; String* secondPermission = reg2->Equals(S"") || reg2 == 0 ? S"null" : reg2; regIdPerm3 = dynamic_cast<RegistryPermission*>(regPerm1->Union(regPerm2)); regIdPerm3 = regPerm1->Union(regPerm2); if(regIdPerm3 == 0) { Console::WriteLine(S"The union of {0} and \n\t{1} is null.", firstPermission, secondPermission); } else { Console::WriteLine(S"The union of {0} and \n\t{1} = \n\t{2}", firstPermission, secondPermission, (dynamic_cast<RegistryPermission*>(regIdPerm3))->GetPathList(RegistryPermissionAccess::Read)); } } catch(Exception* e) { Console::WriteLine(S"An exception was thrown for union :{0}", e); returnValue=false; } } } return returnValue; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
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
RegistryPermission Class | RegistryPermission Members | System.Security.Permissions Namespace