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
)

Parameters

target
Type: System.Security.IPermission

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

Return Value

Type: System.Boolean
false if the current instance is unrestricted and target is either null or unrestricted; otherwise, true.

Implements

IPermission.IsSubsetOf(IPermission)

ExceptionCondition
ArgumentException

target is neither a DnsPermission nor null.

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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft