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)

public override IPermission Union(
	IPermission target
)

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 null, 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 null.

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 void MyUnion()
{
   // Create a DnsPermission instance that is the union of the current DnsPermission 
   // instance and the specified DnsPermission instance.     
   DnsPermission permission = (DnsPermission)dnsPermission1.Union(dnsPermission2);
   // Print the attributes and the values of the union instance of DnsPermission.
   PrintKeysAndValues(permission.ToXml().Attributes);
}
public void 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();
}

private void PrintKeysAndValues(Hashtable myList) {
   // Get the enumerator that can iterate through the hash tabble.
   IDictionaryEnumerator myEnumerator = myList.GetEnumerator();
   Console.WriteLine("\t-KEY-\t-VALUE-");
   while (myEnumerator.MoveNext())
      Console.WriteLine("\t{0}:\t{1}", myEnumerator.Key, myEnumerator.Value);
   Console.WriteLine();
}
   void MyUnion() 
   {
      // Create a DnsPermission instance that is the union of the current DnsPermission
      // instance and the specified DnsPermission instance.
      DnsPermission* permission = dynamic_cast<DnsPermission*>(dnsPermission1->Union(dnsPermission2));
      // Print the attributes and the values of the union instance of DnsPermission.
      PrintKeysAndValues(permission->ToXml()->Attributes);
   }
public:
   void useDns() 
   {
      // Create a DnsPermission instance.
      dnsPermission1 = new DnsPermission(PermissionState::Unrestricted);
      dnsPermission2 = new DnsPermission(PermissionState::None);
      // Check for permission.
      dnsPermission1->Demand();
      dnsPermission2->Demand();
      Console::WriteLine(S"Attributes and Values of first DnsPermission instance :");
      PrintKeysAndValues(dnsPermission1->ToXml()->Attributes);
      Console::WriteLine(S"Attributes and Values of second DnsPermission instance :");
      PrintKeysAndValues(dnsPermission2->ToXml()->Attributes);
      Console::WriteLine(S"Union of both instances : ");
      MyUnion();
      Console::WriteLine(S"Intersection of both instances : ");
      MyIntersection();
   }

private:
   void PrintKeysAndValues(Hashtable* myList) 
   {
      // Get the enumerator that can iterate through the hash tabble.
      IDictionaryEnumerator* myEnumerator = myList->GetEnumerator();
      Console::WriteLine(S"\t-KEY-\t-VALUE-");
      while (myEnumerator->MoveNext())
         Console::WriteLine(S"\t {0}:\t {1}", 
         myEnumerator->Key, myEnumerator->Value);
      Console::WriteLine();
   }

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft