Compartir a través de


ISecurityEncodable.FromXml(SecurityElement) Método

Definición

Reconstruye un objeto de seguridad con un estado especificado a partir de codificación XML.

public:
 void FromXml(System::Security::SecurityElement ^ e);
public void FromXml (System.Security.SecurityElement e);
abstract member FromXml : System.Security.SecurityElement -> unit
Public Sub FromXml (e As SecurityElement)

Parámetros

e
SecurityElement

Codificación XML que se usará para reconstruir el objeto de seguridad.

Ejemplos

En el ejemplo de código siguiente se muestra cómo implementar el FromXml método . Este ejemplo de código es parte de un ejemplo más grande proporcionado para la clase ISecurityEncodable.

    // Populate the permission's fields from XML.
public:
    virtual void FromXml(SecurityElement^ element) override
    {
        specifiedAsUnrestricted = false;
        stateFlags = (SoundPermissionState)0;

        // If XML indicates an unrestricted permission, 
        // make this permission unrestricted.
        String^ attributeString = 
            (String^) element->Attributes["Unrestricted"];
        if (attributeString != nullptr)
        {
            specifiedAsUnrestricted = Convert::ToBoolean(attributeString);
            if (specifiedAsUnrestricted)
            {
                stateFlags = SoundPermissionState::PlayAnySound;
            }
        }

        // If XML indicates a restricted permission, parse the flags.
        if (!specifiedAsUnrestricted)
        {
            attributeString = (String^) element->Attributes["Flags"];
            if (attributeString != nullptr)
            {
                stateFlags = (SoundPermissionState) Convert::ToInt32(
                    Enum::Parse(SoundPermissionState::typeid, 
                    attributeString, true));
            }
        }
    }
// Populate the permission's fields from XML.
public override void FromXml(SecurityElement e)
{
    m_specifiedAsUnrestricted = false;
    m_flags = 0;

    // If XML indicates an unrestricted permission, make this permission unrestricted.
    String s = (String)e.Attributes["Unrestricted"];
    if (s != null)
    {
        m_specifiedAsUnrestricted = Convert.ToBoolean(s);
        if (m_specifiedAsUnrestricted)
            m_flags = SoundPermissionState.PlayAnySound;
    }

    // If XML indicates a restricted permission, parse the flags.
    if (!m_specifiedAsUnrestricted)
    {
        s = (String)e.Attributes["Flags"];
        if (s != null)
        {
            m_flags = (SoundPermissionState)
            Convert.ToInt32(Enum.Parse(typeof(SoundPermission), s, true));
        }
    }
}
' Populate the permission's fields from XML.
Public Overrides Sub FromXml(ByVal e As SecurityElement)
    m_specifiedAsUnrestricted = False
    m_flags = 0

    ' If XML indicates an unrestricted permission, make this permission unrestricted.
    Dim s As String = CStr(e.Attributes("Unrestricted"))
    If Not (s Is Nothing) Then
        m_specifiedAsUnrestricted = Convert.ToBoolean(s)
        If m_specifiedAsUnrestricted Then
            m_flags = SoundPermissionState.PlayAnySound
        End If
    End If
    ' If XML indicates a restricted permission, parse the flags.
    If Not m_specifiedAsUnrestricted Then
        s = CStr(e.Attributes("Flags"))
        If Not (s Is Nothing) Then
            m_flags = CType(Convert.ToInt32([Enum].Parse(GetType(SoundPermission), s, True)), SoundPermissionState)
        End If
    End If

End Sub

Comentarios

El código personalizado que extiende los objetos de seguridad debe implementar los ToXml métodos y FromXml para que los objetos sean codificables por seguridad.

Se aplica a