다음을 통해 공유


DnsPermission.FromXml(SecurityElement) 메서드

정의

XML 인코딩에서 DnsPermission 인스턴스를 다시 생성합니다.

public:
 override void FromXml(System::Security::SecurityElement ^ securityElement);
public override void FromXml (System.Security.SecurityElement securityElement);
override this.FromXml : System.Security.SecurityElement -> unit
Public Overrides Sub FromXml (securityElement As SecurityElement)

매개 변수

securityElement
SecurityElement

DnsPermission 인스턴스를 다시 생성하는 데 사용할 XML 인코딩입니다.

예외

securityElement이(가) null인 경우

securityElementDnsPermission 요소가 아닌 경우

예제

다음 예제에서는 XML 인코딩에서 인스턴스를 다시 구성 DnsPermission 합니다.

public:
   void ConstructDnsPermission()
   {
      try
      {
         // Create a DnsPermission instance.
         DnsPermission^ permission = gcnew DnsPermission( PermissionState::None );
         // Create a SecurityElement instance by calling the ToXml method on the
         // DnsPermission instance.
         // Print its attributes, which hold the  XML encoding of the DnsPermission
         // instance.
         Console::WriteLine( "Attributes and Values of 'DnsPermission' instance :" );
         PrintKeysAndValues( permission->ToXml()->Attributes );
         
         // Create a SecurityElement instance.
         SecurityElement^ securityElementObj = gcnew SecurityElement( "IPermission" );
         // Add attributes and values of the SecurityElement instance corresponding to
         // the permission instance.
         securityElementObj->AddAttribute( "version", "1" );
         securityElementObj->AddAttribute( "Unrestricted", "true" );
         securityElementObj->AddAttribute( "class", "System.Net.DnsPermission" );
         
         // Reconstruct a DnsPermission instance from an XML encoding.
         DnsPermission^ permission1 = gcnew DnsPermission( PermissionState::None );
         permission1->FromXml( securityElementObj );
         
         // Print the attributes and values of the constructed DnsPermission Object*.
         Console::WriteLine( "After reconstruction Attributes and Values of new DnsPermission instance :" );
         PrintKeysAndValues( permission1->ToXml()->Attributes );
      }
      catch ( NullReferenceException^ e ) 
      {
         Console::WriteLine( "NullReferenceException caught!!!" );
         Console::WriteLine( "Source : {0}", e->Source );
         Console::WriteLine( "Message : {0}", e->Message );
      }
      catch ( SecurityException^ e ) 
      {
         Console::WriteLine( "SecurityException caught!!!" );
         Console::WriteLine( "Source : {0}", e->Source );
         Console::WriteLine( "Message : {0}", e->Message );
      }
      catch ( ArgumentNullException^ e ) 
      {
         Console::WriteLine( "ArgumentNullException caught!!!" );
         Console::WriteLine( "Source : {0}", e->Source );
         Console::WriteLine( "Message : {0}", e->Message );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Exception caught!!!" );
         Console::WriteLine( "Source : {0}", e->Source );
         Console::WriteLine( "Message : {0}", e->Message );
      }
   }

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 void ConstructDnsPermission() {
  try
  {
    // Create a DnsPermission instance.
    DnsPermission permission = new DnsPermission(PermissionState.None);
    // Create a SecurityElement instance by calling the ToXml method on the
    // DnsPermission instance.
    // Print its attributes, which hold the  XML encoding of the DnsPermission
    // instance.
    Console.WriteLine("Attributes and Values of 'DnsPermission' instance :");
    PrintKeysAndValues(permission.ToXml().Attributes);

    // Create a SecurityElement instance.
    SecurityElement securityElementObj = new SecurityElement("IPermission");
    // Add attributes and values of the SecurityElement instance corresponding to
    // the permission instance.
    securityElementObj.AddAttribute("version", "1");
    securityElementObj.AddAttribute("Unrestricted", "true");
    securityElementObj.AddAttribute("class","System.Net.DnsPermission");

    // Reconstruct a DnsPermission instance from an XML encoding.
      DnsPermission permission1 = new DnsPermission(PermissionState.None);
    permission1.FromXml(securityElementObj);

    // Print the attributes and values of the constructed DnsPermission object.
    Console.WriteLine("After reconstruction Attributes and Values of new DnsPermission instance :");
    PrintKeysAndValues(permission1.ToXml().Attributes);
  }
  catch(NullReferenceException e)
  {
    Console.WriteLine("NullReferenceException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
  }
  catch(SecurityException e)
  {
    Console.WriteLine("SecurityException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
  }
  catch(ArgumentNullException e)
  {
    Console.WriteLine("ArgumentNullException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
  }
  catch(Exception e)
  {
    Console.WriteLine("Exception caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
  }
}

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 ConstructDnsPermission()
    Try
        ' Create a DnsPermission instance.
        Dim permission As New DnsPermission(PermissionState.None)
        ' Create a SecurityElement instance by calling the ToXml method on the
        ' DnsPermission instance and print its attributes, 
        ' which hold the  XML encoding of the DnsPermission instance.
        Console.WriteLine("Attributes and Values of 'DnsPermission' instance :")
        PrintKeysAndValues(permission.ToXml().Attributes)
        
        ' Create a SecurityElement instacnce .
        Dim securityElementObj As New SecurityElement("IPermission")
        ' Add attributes and values of the SecurityElement instance corresponding to
        ' the permission instance.
        securityElementObj.AddAttribute("version", "1")
        securityElementObj.AddAttribute("Unrestricted", "true")
        securityElementObj.AddAttribute("class", "System.Net.DnsPermission")
        
        ' Reconstruct a DnsPermission instance from an XML encoding.
        Dim permission1 As New DnsPermission(PermissionState.None)
        permission1.FromXml(securityElementObj)
        
        ' Print the attributes and values of the constructed DnsPermission object.
        Console.WriteLine("After reconstruction Attributes and Values of new DnsPermission instance :")
        PrintKeysAndValues(permission1.ToXml().Attributes)
    Catch e As NullReferenceException
        Console.WriteLine("NullReferenceException caught!!!")
        Console.WriteLine(("Source : " + e.Source))
        Console.WriteLine(("Message : " + e.Message))
    Catch e As SecurityException
        Console.WriteLine("SecurityException caught!!!")
        Console.WriteLine(("Source : " + e.Source))
        Console.WriteLine(("Message : " + e.Message))
    Catch e As ArgumentNullException
        Console.WriteLine("ArgumentNullException caught!!!")
        Console.WriteLine(("Source : " + e.Source))
        Console.WriteLine(("Message : " + e.Message))
    Catch e As Exception
        Console.WriteLine("Exception caught!!!")
        Console.WriteLine(("Source : " + e.Source))
        Console.WriteLine(("Message : " + e.Message))
    End Try
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

설명

메서드는 FromXml 클래스에 의해 SecurityElement 정의된 XML 인코딩에서 인스턴스를 다시 구성 DnsPermission 합니다.

메서드를 ToXml 사용하여 상태 정보를 포함하여 인스턴스를 DnsPermission XML로 인코딩합니다.

적용 대상

추가 정보