Freigeben über


ISecurityEncodable.ToXml-Methode

Erstellt eine XML-Codierung des Sicherheitsobjekts und seines aktuellen Zustands.

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

Syntax

'Declaration
Function ToXml As SecurityElement
'Usage
Dim instance As ISecurityEncodable
Dim returnValue As SecurityElement

returnValue = instance.ToXml
SecurityElement ToXml ()
SecurityElement^ ToXml ()
SecurityElement ToXml ()
function ToXml () : SecurityElement

Rückgabewert

Eine XML-Codierung des Sicherheitsobjekts, einschließlich aller Zustandsinformationen.

Hinweise

In benutzerdefiniertem Code, der Sicherheitsobjekte erweitert, müssen die ToXml-Methode und die FromXml-Methode implementiert werden, um eine Sicherheitscodierung der Objekte zu ermöglichen.

Beispiel

Im folgenden Codebeispiel wird das Implementieren der FromXml-Methode veranschaulicht. Dieses Codebeispiel ist Teil eines umfangreicheren Beispiels für die ISecurityEncodable-Klasse.

// Produce XML from the permission's fields.
public override SecurityElement ToXml() {
    // These first three lines create an element with the required format.
    SecurityElement e = new SecurityElement("IPermission");
    // Replace the double quotation marks () with single quotation marks ()
    // to remain XML compliant when the culture is not neutral.
    e.AddAttribute("class", GetType().AssemblyQualifiedName.Replace('\"', '\''));
    e.AddAttribute("version", "1");

    if (!m_specifiedAsUnrestricted)
        e.AddAttribute("Flags", Enum.Format(typeof(SoundPermission), m_flags, "G"));
    else
        e.AddAttribute("Unrestricted", "true");
    return e;
}
    // Produce XML from the permission's fields.
public:
    virtual SecurityElement^ ToXml() override
    {
        // These first three lines create an element with the required format.
        SecurityElement^ element = gcnew SecurityElement("IPermission");
        // Replace the double quotation marks () 
        // with single quotation marks ()
        // to remain XML compliant when the culture is not neutral.
        element->AddAttribute("class", 
            GetType()->AssemblyQualifiedName->Replace('\"', '\''));
        element->AddAttribute("version", "1");

        if (!specifiedAsUnrestricted)
        {
            element->AddAttribute("Flags", 
                Enum::Format(SoundPermissionState::typeid, stateFlags, "G"));
        }   
        else
        {
            element->AddAttribute("Unrestricted", "true");
        }
        return element;
    }

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

ISecurityEncodable-Schnittstelle
ISecurityEncodable-Member
System.Security-Namespace