Bagikan melalui


DnsPermission.Union(IPermission) Metode

Definisi

Membuat instans izin yang merupakan gabungan instans izin saat ini dan instans izin yang ditentukan.

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

Parameter

target
IPermission

Instans DnsPermission untuk digabungkan dengan instans saat ini.

Mengembalikan

DnsPermission Instans yang mewakili gabungan instans saat ini DnsPermission dengan instans yang ditentukanDnsPermission. Jika target adalah null, metode ini mengembalikan salinan instans saat ini. Jika instans saat ini atau target tidak dibatasi, metode ini mengembalikan instans DnsPermission yang tidak dibatasi; jika tidak, instans akan mengembalikan instans DnsPermission yang dibatasi.

Pengecualian

target bukan juga DnsPermissionnull.

Contoh

Contoh berikut membuat instans izin yang merupakan gabungan instans izin saat ini dan instans izin yang ditentukan.

private:
   void MyUnion()
   {
      // Create a DnsPermission instance that is the union of the current DnsPermission
      // instance and the specified DnsPermission instance.
      DnsPermission^ permission = dynamic_cast<DnsPermission^>(dnsPermission1->Union( dnsPermission2 ));
      // Print the attributes and the values of the union instance of DnsPermission.
      PrintKeysAndValues( permission->ToXml()->Attributes );
   }

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();
   }
private void MyUnion()
{
   // Create a DnsPermission instance that is the union of the current DnsPermission
   // instance and the specified DnsPermission instance.
   DnsPermission permission = (DnsPermission)dnsPermission1.Union(dnsPermission2);
   // Print the attributes and the values of the union 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();
}
Private Sub MyUnion()
    ' Create a DnsPermission instance which is the union of the current DnsPermission instance and the specified DnsPermission instance.
    Dim permission As DnsPermission = CType(dnsPermission1.Union(dnsPermission2), DnsPermission)
    ' Print the attributes and values of the union instance of DnsPermission.
    PrintKeysAndValues(permission.ToXml().Attributes)
End Sub
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

Keterangan

Metode mengembalikan Union instans yang memungkinkan akses yang ditentukan oleh instans DnsPermission saat ini DnsPermission atau instans yang ditentukan DnsPermission . Setiap permintaan yang melewati salah satu izin melewati persatuan mereka.

Berlaku untuk