共用方式為


DnsPermission.Intersect(IPermission) 方法

定義

建立使用權限執行個體,這個使用權限執行個體是目前使用權限執行個體和指定使用權限執行個體的交集。

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

參數

target
IPermission

DnsPermission 執行個體,用來與目前執行個體交集。

傳回

DnsPermission 執行個體,表示目前 DnsPermission 執行個體和指定 DnsPermission 執行個體的交集,或 null (如果交集為空)。 如果目前執行個體和 target 都是不受限制的,則這個方法會傳回不受限制的新 DnsPermission 執行個體,否則傳回 null

例外狀況

target 既不是 DnsPermission 也不是 null

範例

下列範例會建立許可權實例,這個實例是目前許可權實例和指定許可權實例的交集。

public:
   void useDns()
   {
      // Create a DnsPermission instance.
      dnsPermission1 = gcnew DnsPermission( PermissionState::Unrestricted );
      dnsPermission2 = gcnew 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.
   void MyIntersection()
   {
      DnsPermission^ permission = dynamic_cast<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().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 Sub 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()
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

Private Sub MyIntersection()
    ' Create a DnsPermission instance that is the intersection of the current
    ' DnsPermission instance and the specified DnsPermission instance.
    Dim permission As DnsPermission = CType(dnsPermission1.Intersect(dnsPermission2), DnsPermission)
    ' Print the attributes and values of the intersection instance of DnsPermission.
    PrintKeysAndValues(permission.ToXml().Attributes)
End Sub

備註

方法 Intersect 會傳 DnsPermission 回 實例,允許目前 DnsPermission 實例和指定 DnsPermission 實例所定義的存取。 任何需求都必須傳遞這兩個許可權,才能傳遞其交集。

適用於