Aracılığıyla paylaş


DnsPermission.Copy Yöntem

Tanım

Geçerli izin örneğinin özdeş bir kopyasını oluşturur.

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

Döndürülenler

Geçerli örneğin özdeş DnsPermission bir kopyası olan sınıfının yeni bir örneği.

Örnekler

Aşağıdaki örnek, mevcut DnsPermission örneğin özdeş bir kopyasını oluşturur.

public:
   void UseDns()
   {
      // Create a DnsPermission instance.
      DnsPermission^ myPermission = gcnew DnsPermission( PermissionState::Unrestricted );
      // Check for permission.
      myPermission->Demand();
      // Create an identical copy of the above 'DnsPermission' Object*.
      DnsPermission^ myPermissionCopy = dynamic_cast<DnsPermission^>(myPermission->Copy());
      Console::WriteLine( "Attributes and Values of 'DnsPermission' instance :" );
      // Print the attributes and values.
      PrintKeysAndValues( myPermission->ToXml()->Attributes );
      Console::WriteLine( "Attribute and values of copied instance :" );
      PrintKeysAndValues( myPermissionCopy->ToXml()->Attributes );
   }

private:
   void PrintKeysAndValues( Hashtable^ myHashtable )
   {
      // Get the enumerator that can iterate through the hash table.
      IDictionaryEnumerator^ myEnumerator = myHashtable->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.
   DnsPermission myPermission = new DnsPermission(PermissionState.Unrestricted);
   // Check for permission.
   myPermission.Demand();
   // Create an identical copy of the above 'DnsPermission' object.
   DnsPermission myPermissionCopy = (DnsPermission)myPermission.Copy();
   Console.WriteLine("Attributes and Values of 'DnsPermission' instance :");
   // Print the attributes and values.
   PrintKeysAndValues(myPermission.ToXml().Attributes);
   Console.WriteLine("Attribute and values of copied instance :");
   PrintKeysAndValues(myPermissionCopy.ToXml().Attributes);
}

private void PrintKeysAndValues(Hashtable myHashtable) {
   // Get the enumerator that can iterate through the hash table.
   IDictionaryEnumerator myEnumerator = myHashtable.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.
    Dim myPermission As New DnsPermission(PermissionState.Unrestricted)
    ' Check for permission.
    myPermission.Demand()
    ' Create an identical copy of the above DnsPermission object.
    Dim myPermissionCopy As DnsPermission = CType(myPermission.Copy(), DnsPermission)
    Console.WriteLine("Attributes and Values of 'DnsPermission' instance :")
    ' Print the attributes and values.
    PrintKeysAndValues(myPermission.ToXml().Attributes)
    Console.WriteLine("Attribute and values of copied instance :")
    PrintKeysAndValues(myPermissionCopy.ToXml().Attributes)
End Sub


Private Sub PrintKeysAndValues(myHashtable As Hashtable)
    ' Get the enumerator that can iterate through he hash table.
    Dim myEnumerator As IDictionaryEnumerator = myHashtable.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

Açıklamalar

Örneğin kopyası DnsPermission , DNS sunucularına özgün izin örneğiyle aynı erişimi sağlar.

Şunlara uygulanır