Export (0) Print
Expand All

DnsPermission.Intersect Method

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

[Visual Basic]
Overrides Public Function Intersect( _
   ByVal target As IPermission _
) As IPermission Implements IPermission.Intersect
[C#]
public override IPermission Intersect(
 IPermission target
);
[C++]
public: IPermission* Intersect(
 IPermission* target
);
[JScript]
public override function Intersect(
   target : IPermission
) : IPermission;

Parameters

target
The DnsPermission instance to combine with the current instance.

Return Value

A DnsPermission instance that represents the intersection of the current DnsPermission instance with the specified DnsPermission instance, or a null reference (Nothing in Visual Basic) if the intersection is empty. If both the current instance and target are unrestricted, this method returns a new DnsPermission instance that is unrestricted; otherwise, it returns a null reference (Nothing).

Implements

IPermission.Intersect

Exceptions

Exception Type Condition
ArgumentException target is neither a DnsPermission nor a null reference (Nothing in Visual Basic).

Remarks

The Intersect method returns a DnsPermission instance that allows the access defined by both the current DnsPermission instance and the specified DnsPermission instance. Any demand must pass both permissions to pass their intersection.

Example

[Visual Basic, C#, C++] The following example creates a permission instance that is the intersection of the current permission instance and the specified permission instance.

[Visual Basic] 
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

Private Sub MyIntersection()
    ' Create a DnsPermission instance that is the intersection of the current
    ' DnsPermission instance and the specified DnsPermission instance.
    Dim permission As DnsPermission = CType(dnsPermission1.Intersect(dnsPermission2), DnsPermission)
    ' Print the attributes and values of the intersection instance of DnsPermission.
    PrintKeysAndValues(permission.ToXml().Attributes)
End Sub 'MyIntersection

[C#] 
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();
}
   // Create a DnsPermission instance that is the intersection of current
   // DnsPermission instance and the specified DnsPermission instance.
private void MyIntersection()
{
   DnsPermission permission = (DnsPermission)dnsPermission1.Intersect(dnsPermission2);
   // Print the attributes and the values of the intersection instance of
   // DnsPermission.
   PrintKeysAndValues(permission.ToXml().Attributes);
}

[C++] 
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();
   }
   // Create a DnsPermission instance that is the intersection of current
   // DnsPermission instance and the specified DnsPermission instance.
private:
   void MyIntersection() 
   {
      DnsPermission* permission = 
         dynamic_cast<DnsPermission*>(dnsPermission1->Intersect(dnsPermission2));
      // Print the attributes and the values of the intersection instance of
      // DnsPermission.
      PrintKeysAndValues(permission->ToXml()->Attributes);
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter 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, Common Language Infrastructure (CLI) Standard

See Also

DnsPermission Class | DnsPermission Members | System.Net Namespace

Show:
© 2015 Microsoft