DnsPermission.IsSubsetOf(IPermission) 方法

定义

确定当前权限实例是否是指定权限实例的子集。

public:
 override bool IsSubsetOf(System::Security::IPermission ^ target);
public override bool IsSubsetOf (System.Security.IPermission target);
override this.IsSubsetOf : System.Security.IPermission -> bool
Public Overrides Function IsSubsetOf (target As IPermission) As Boolean

参数

target
IPermission

第二个需测试子集关系的 DnsPermission 实例。

返回

如果当前实例是不受限制的,并且 target 或者为 false 或者是不受限制的,则为 null;否则,为 true

例外

target 既不是 DnsPermission,也不是 null

示例

以下示例使用 IsSubsetOf 方法确定当前权限实例是否为指定权限实例的子集。

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("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 Sub useDns()
    ' Create a DnsPermission instance.
    permission = New DnsPermission(PermissionState.Unrestricted)
    Dim dnsPermission1 As 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)
End Sub


Private Sub Subset(Permission1 As DnsPermission)
    If permission.IsSubsetOf(Permission1) Then
        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.")
    End If
End Sub
 
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

注解

如果当前 DnsPermission 实例指定由指定 DnsPermission 实例完全包含的一组操作,则当前 DnsPermission 实例是指定 DnsPermission 实例的子集。

IsSubsetOf如果方法返回 true,则当前DnsPermission实例所允许的 DNS 服务器访问权限不会超过指定的DnsPermission实例。

适用于