This documentation is archived and is not being maintained.

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:
virtual bool IsSubsetOf(
	IPermission^ target
) override

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 nullptr or unrestricted; otherwise, true.

Implements

IPermission::IsSubsetOf(IPermission)

ExceptionCondition
ArgumentException

target is neither a DnsPermission nor nullptr.

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 = gcnew DnsPermission( PermissionState::Unrestricted );
      DnsPermission^ dnsPermission1 = gcnew 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." );
      }
   }

   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(S"Attributes and Values of 'DnsPermission' instance :");
      PrintKeysAndValues(permission->ToXml()->Attributes);
      Console::WriteLine(S"Attributes and Values of specified 'DnsPermission' instance :");
      PrintKeysAndValues(dnsPermission1->ToXml()->Attributes);
      Subset(dnsPermission1);
   }

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

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