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.

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

public override IPermission Intersect (
	IPermission target
)
public IPermission Intersect (
	IPermission target
)
public override function Intersect (
	target : IPermission
) : IPermission

Parameters

target

The DnsPermission instance to intersect 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 in Visual Basic).

Exception typeCondition

ArgumentException

target is neither a DnsPermission nor a null reference (Nothing in Visual Basic).

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.

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

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);
}

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().get_Attributes());
    Console.WriteLine("Attributes and Values of second DnsPermission "
        + "instance :");
    PrintKeysAndValues(dnsPermission2.ToXml().get_Attributes());
    Console.WriteLine("Union of both instances : ");
    MyUnion();
    Console.WriteLine("Intersection of both instances : ");
    MyIntersection();
} //UseDns

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.get_Key(),
            myEnumerator.get_Value());
    }
    Console.WriteLine();
} //PrintKeysAndValues

// 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().get_Attributes());
} //MyIntersection

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

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft