Export (0) Print
Expand All

DnsPermission.Union Method

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

Namespace:  System.Net
Assembly:  System (in System.dll)

'Declaration
Public Overrides Function Union ( _
	target As IPermission _
) As IPermission

Parameters

target
Type: System.Security.IPermission

The DnsPermission instance to combine with the current instance.

Return Value

Type: System.Security.IPermission
A DnsPermission instance that represents the union of the current DnsPermission instance with the specified DnsPermission instance. If target is Nothing, this method returns a copy of the current instance. If the current instance or target is unrestricted, this method returns a DnsPermission instance that is unrestricted; otherwise, it returns a DnsPermission instance that is restricted.

Implements

IPermission.Union(IPermission)

ExceptionCondition
ArgumentException

target is neither a DnsPermission nor Nothing.

The Union method returns a DnsPermission instance that allows the access defined by either the current DnsPermission instance or the specified DnsPermission instance. Any demand that passes either permission passes their union.

The following example creates a permission instance that is the union of the current permission instance and the specified permission instance.

Private Sub MyUnion()
    ' Create a DnsPermission instance which is the union of the current DnsPermission instance and the specified DnsPermission instance. 
    Dim permission As DnsPermission = CType(dnsPermission1.Union(dnsPermission2), DnsPermission)
    ' Print the attributes and values of the union instance of DnsPermission.
    PrintKeysAndValues(permission.ToXml().Attributes)
End Sub 'MyUnion
Public Sub useDns()
    ' Create a DnsPermission instance.
    dnsPermission1 = New DnsPermission(PermissionState.Unrestricted)
    dnsPermission2 = New DnsPermission(PermissionState.None)
    ' Check for permission.
    dnsPermission1.Demand()
    dnsPermission2.Demand()
    Console.WriteLine("Attributes and Values of first DnsPermission instance :")
    PrintKeysAndValues(dnsPermission1.ToXml().Attributes)
    Console.WriteLine("Attributes and Values of second DnsPermission instance :")
    PrintKeysAndValues(dnsPermission2.ToXml().Attributes)
    Console.WriteLine("Union of both instances : ")
    MyUnion()
    Console.WriteLine("Intersection of both instances : ")
    MyIntersection()
End Sub 'useDns

Private Sub PrintKeysAndValues(myList As Hashtable)
    ' Get the enumerator that can iterate through the hash table. 
    Dim myEnumerator As IDictionaryEnumerator = myList.GetEnumerator()
    Console.WriteLine(ControlChars.Tab + "-KEY-" + ControlChars.Tab + "-VALUE-")
    While myEnumerator.MoveNext()
        Console.WriteLine(ControlChars.Tab + "{0}:" + ControlChars.Tab + "{1}", myEnumerator.Key, myEnumerator.Value)
    End While
    Console.WriteLine()
End Sub 'PrintKeysAndValues

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft