Freigeben über


SecurityPermission.ToXml-Methode

Erstellt eine XML-Codierung der Berechtigung und ihres aktuellen Zustands.

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overrides Function ToXml As SecurityElement
'Usage
Dim instance As SecurityPermission
Dim returnValue As SecurityElement

returnValue = instance.ToXml
public override SecurityElement ToXml ()
public:
virtual SecurityElement^ ToXml () override
public SecurityElement ToXml ()
public override function ToXml () : SecurityElement

Rückgabewert

Eine XML-Codierung der Berechtigung, einschließlich sämtlicher Zustandsinformationen.

Beispiel

Im folgenden Codebeispiel soll das Verhalten der ToXml-Methode veranschaulicht werden, auf ihre Verwendung wird jedoch nicht eingegangen. Im Allgemeinen werden die Methoden von Berechtigungsklassen durch die Sicherheitsinfrastruktur verwendet und sind nicht für die Verwendung in Anwendungen bestimmt. Im folgenden Codebeispiel wird jedoch veranschaulicht, wie sich die Methode verhält, wenn sie vom Code aus ausgeführt wird. Den vollständigen Beispielcode finden Sie in der SecurityPermission-Klasse.

    Private Function ToFromXmlDemo() As Boolean

        Dim returnValue As Boolean = True

        Dim Security1 As SecurityPermissionFlag
        Dim SecurityPerm1, SecurityPerm2 As SecurityPermission
        Dim SecurityGen1 As New SecurityGenerator()
        Dim SecurityGen2 As New SecurityGenerator()
        SecurityGen1.ResetIndex()
        While SecurityGen1.GetSecurityFlag(Security1)
            SecurityPerm1 = New SecurityPermission(Security1)
            Console.WriteLine("********************************************************" & ControlChars.Lf)
            SecurityGen2.ResetIndex()
            Try
                SecurityPerm2 = New SecurityPermission(PermissionState.None)
                SecurityPerm2.FromXml(SecurityPerm1.ToXml())
                Console.WriteLine(("Result of ToFromXml = " & SecurityPerm2.ToString()))

            Catch e As Exception
                Console.WriteLine(("ToFromXml failed :" & SecurityPerm1.ToString() & e.ToString()))
                GoTo ContinueWhile1
            End Try
ContinueWhile1:
        End While

        Return returnValue
    End Function 'ToFromXmlDemo
private bool ToFromXmlDemo()
{

    bool returnValue = true;

    SecurityPermissionFlag security1;
    SecurityPermission securityPerm1,securityPerm2;
    SecurityGenerator SecurityGen1 = new SecurityGenerator();
    SecurityGenerator SecurityGen2 = new SecurityGenerator();
    SecurityGen1.ResetIndex();
    while(SecurityGen1.GetSecurityFlag( out security1 ))
    {
        securityPerm1 = new SecurityPermission(security1);
        Console.WriteLine("********************************************************\n");
        SecurityGen2.ResetIndex();
        try
        {
            securityPerm2= new SecurityPermission(PermissionState.None);
            securityPerm2.FromXml(securityPerm1.ToXml());
            Console.WriteLine("Result of ToFromXml = " +
                securityPerm2.ToString());

        }
        catch(Exception e)
        {
            Console.WriteLine("ToFromXml failed :" + securityPerm1.ToString() + e);
            continue;
        }
    }

    return returnValue;

}
   bool ToFromXmlDemo()
   {
      bool returnValue = true;
      SecurityPermissionFlag security1;
      SecurityPermission^ securityPerm1;
      SecurityPermission^ securityPerm2;
      SecurityGenerator^ SecurityGen1 = gcnew SecurityGenerator;
      SecurityGenerator^ SecurityGen2 = gcnew SecurityGenerator;
      SecurityGen1->ResetIndex();
      while ( SecurityGen1->GetSecurityFlag( &security1 ) )
      {
         securityPerm1 = gcnew SecurityPermission(security1);
                  continue;

         Console::WriteLine( "********************************************************\n" );
         SecurityGen2->ResetIndex();
         try
         {
            securityPerm2 = gcnew SecurityPermission( PermissionState::None );
            securityPerm2->FromXml( securityPerm1->ToXml() );
            Console::WriteLine( "Result of ToFromXml = {0}", securityPerm2 );
         }
         catch ( Exception^ e ) 
         {
            Console::WriteLine( "ToFromXml failed :{0}{1}", securityPerm1, e );
            continue;
         }

      }

      return returnValue;
   }


public:
private boolean ToFromXmlDemo() 
{
    boolean returnValue = true;
       SecurityPermissionFlag security1[] = new SecurityPermissionFlag[1];
    SecurityPermission securityPerm1[] = new SecurityPermission[1];
    SecurityPermission securityPerm2[] = new SecurityPermission[1];
    SecurityGenerator securityGen1 =  new SecurityGenerator();
    SecurityGenerator securityGen2 =  new SecurityGenerator();
    securityGen1.ResetIndex();
    while (securityGen1.CreateSecurity(securityPerm1, security1)) {
        if (securityPerm1[0] == null) {
            continue ;
        }
        Console.WriteLine("*****************************" 
            + "***************************\n");
        securityGen2.ResetIndex();
        try {
            securityPerm2[0] = 
                new SecurityPermission(PermissionState.None);
            securityPerm2[0].FromXml(securityPerm1[0].ToXml());
            Console.WriteLine(("Result of ToFromXml = " 
                + securityPerm2[0].ToString()));
        }        
        catch(System.Exception e) {
            Console.WriteLine(("ToFromXml failed :" 
                + securityPerm1[0].ToString() + e));
            continue ;
        }
    }      
    return returnValue ;
} //ToFromXmlDemo

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

SecurityPermission-Klasse
SecurityPermission-Member
System.Security.Permissions-Namespace