Export (0) Print
Expand All

DnsPermission.IsSubsetOf Method

Determines whether the current permission instance is a subset of the specified permission instance.

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

public override bool IsSubsetOf (
	IPermission target
)
public boolean IsSubsetOf (
	IPermission target
)
public override function IsSubsetOf (
	target : IPermission
) : boolean
Not applicable.

Parameters

target

The second DnsPermission instance to be tested for the subset relationship.

Return Value

false if the current instance is unrestricted and target is either a null reference (Nothing in Visual Basic) or unrestricted; otherwise, true.

Exception typeCondition

ArgumentException

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

The current DnsPermission instance is a subset of the specified DnsPermission instance if the current DnsPermission instance specifies a set of operations that is wholly contained by the specified DnsPermission instance.

If the IsSubsetOf method returns true, the current DnsPermission instance allows no more access to DNS servers than does the specified DnsPermission instance.

The following example uses the IsSubsetOf method to determine whether the current permission instance is a subset of the specified permission instance.

public void useDns() {
   // Create a DnsPermission instance.
   permission = new DnsPermission(PermissionState.Unrestricted);
   DnsPermission dnsPermission1 = new DnsPermission(PermissionState.None);
   // Check for permission.
   permission.Demand();
   dnsPermission1.Demand();
   // Print the attributes and values.
   Console.WriteLine("Attributes and Values of 'DnsPermission' instance :");
   PrintKeysAndValues(permission.ToXml().Attributes);
   Console.WriteLine("Attributes and Values of specified 'DnsPermission' instance :");
   PrintKeysAndValues(dnsPermission1.ToXml().Attributes);
   Subset(dnsPermission1);
}

private void Subset(DnsPermission Permission1)
{
   if(permission.IsSubsetOf(Permission1))
      Console.WriteLine("Current 'DnsPermission' instance is a subset of specified 'DnsPermission' instance.");
   else
      Console.WriteLine("Current 'DnsPermission' instance is not a subset of specified 'DnsPermission' instance.");
}

private void PrintKeysAndValues(Hashtable myList) {
   // Get the enumerator that can iterate through the hash table.
   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();
}

public void UseDns()
{
    // Create a DnsPermission instance.
    permission = new DnsPermission(PermissionState.Unrestricted);
    DnsPermission dnsPermission1 = new DnsPermission(PermissionState.None);

    // Check for permission.
    permission.Demand();
    dnsPermission1.Demand();

    // Print the attributes and values.
    Console.WriteLine("Attributes and Values of 'DnsPermission' "
        + "instance :");
    PrintKeysAndValues(permission.ToXml().get_Attributes());
    Console.WriteLine("Attributes and Values of specified "
        + "'DnsPermission' instance :");
    PrintKeysAndValues(dnsPermission1.ToXml().get_Attributes());
    Subset(dnsPermission1);
} //UseDns

private void Subset(DnsPermission Permission1)
{
    if (permission.IsSubsetOf(Permission1)) {
        Console.WriteLine("Current 'DnsPermission' instance is a "
            + "subset of specified 'DnsPermission' instance.");
    }
    else {
        Console.WriteLine("Current 'DnsPermission' instance is "
            + "not a subset of specified 'DnsPermission' instance.");
    }
} //Subset

private void PrintKeysAndValues(Hashtable myList)
{
    // Get the enumerator that can iterate through the hash table.
    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

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft