Compartilhar via


AsymmetricAlgorithm.FromXmlString(String) Método

Definição

Quando substituído em uma classe derivada, recria um objeto AsymmetricAlgorithm de uma cadeia de caracteres XML. Caso contrário, gerará um NotImplementedException.

public:
 virtual void FromXmlString(System::String ^ xmlString);
public:
 abstract void FromXmlString(System::String ^ xmlString);
public virtual void FromXmlString (string xmlString);
public abstract void FromXmlString (string xmlString);
abstract member FromXmlString : string -> unit
override this.FromXmlString : string -> unit
abstract member FromXmlString : string -> unit
Public Overridable Sub FromXmlString (xmlString As String)
Public MustOverride Sub FromXmlString (xmlString As String)

Parâmetros

xmlString
String

A cadeia de caracteres XML a ser usada para reconstruir o objeto AsymmetricAlgorithm.

Exemplos

O exemplo de código a seguir demonstra como implementar o FromXmlString método para analisar a cadeia de caracteres XML especificada para preencher o objeto atual CspParameters . Este exemplo de código faz parte de um exemplo maior fornecido para a AsymmetricAlgorithm classe .

    // Expected XML schema:
    //      <ProviderName></ProviderName>
    //      <KeyContainerName></KeyContainerName>
    //      <KeyNumber></KeyNumber>
    //      <ProviderType></ProviderType>
public:
    virtual void FromXmlString(String^ xmlString) override 
    {
        if (xmlString != nullptr)
        {
            XmlDocument^ document = gcnew XmlDocument();
            document->LoadXml(xmlString);
            XmlNode^ firstNode = document->FirstChild;
            XmlNodeList^ nodeList;

            // Assemble parameters from values in each XML element.
            cryptoServiceParameters = gcnew CspParameters();

            // KeyContainerName is optional.
            nodeList = 
                document->GetElementsByTagName("KeyContainerName");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->KeyContainerName =
                    nodeList->Item(0)->InnerText;
            }

            // KeyNumber is optional.
            nodeList = document->GetElementsByTagName("KeyNumber");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->KeyNumber =
                    Int32::Parse(nodeList->Item(0)->InnerText);
            }

            // ProviderName is optional.
            nodeList = document->GetElementsByTagName("ProviderName");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->ProviderName =
                    nodeList->Item(0)->InnerText;
            }

            // ProviderType is optional.
            nodeList = document->GetElementsByTagName("ProviderType");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->ProviderType =
                    Int32::Parse(nodeList->Item(0)->InnerText);
            }
        }
        else
        {
            throw gcnew ArgumentNullException("xmlString");
        }
    }
// Expected XML schema:
//      <ProviderName></ProviderName>
//      <KeyContainerName></KeyContainerName>
//      <KeyNumber></KeyNumber>
//      <ProviderType></ProviderType>
public override void FromXmlString(string xmlString)
{
    if (xmlString != null)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xmlString);
        XmlNode firstNode = doc.FirstChild;
        XmlNodeList nodeList;

        // Assemble parameters from values in each XML element.
        cspParameters = new CspParameters();

        // KeyContainerName is optional.
        nodeList = doc.GetElementsByTagName("KeyContainerName");
        string keyName = nodeList.Item(0).InnerText;
        if (keyName != null) 
        {
            cspParameters.KeyContainerName = keyName;
        }

        // KeyNumber is optional.
        nodeList = doc.GetElementsByTagName("KeyNumber");
        string keyNumber = nodeList.Item(0).InnerText;
        if (keyNumber != null) 
        {
            cspParameters.KeyNumber = Int32.Parse(keyNumber);
        }

        // ProviderName is optional.
        nodeList = doc.GetElementsByTagName("ProviderName");
        string providerName = nodeList.Item(0).InnerText;
        if (providerName != null) 
        {
            cspParameters.ProviderName = providerName;
        }

        // ProviderType is optional.
        nodeList = doc.GetElementsByTagName("ProviderType");
        string providerType = nodeList.Item(0).InnerText;
        if (providerType != null) 
        {
            cspParameters.ProviderType = Int32.Parse(providerType);
        }
    }
    else
    {
        throw new ArgumentNullException("xmlString");
    }
}
' Expected XML schema:
'      <ProviderName></ProviderName>
'      <KeyContainerName></KeyContainerName>
'      <KeyNumber></KeyNumber>
'      <ProviderType></ProviderType>
Public Overrides Sub FromXmlString(ByVal xmlString As String)
    If Not xmlString Is Nothing Then
        Dim doc As New XmlDocument
        doc.LoadXml(xmlString)
        Dim firstNode As XmlNode = doc.FirstChild
        Dim nodeList As XmlNodeList

        ' Assemble parameters from values in each XML element.
        cspParameters = New CspParameters

        ' KeyContainerName is optional.
        nodeList = doc.GetElementsByTagName("KeyContainerName")
        Dim keyName As String = nodeList.Item(0).InnerText
        If Not keyName Is Nothing Then
            cspParameters.KeyContainerName = keyName
        End If

        ' KeyNumber is optional.
        nodeList = doc.GetElementsByTagName("KeyNumber")
        Dim keyNumber As String = nodeList.Item(0).InnerText
        If Not keyNumber Is Nothing Then
            cspParameters.KeyNumber = Int32.Parse(keyNumber)
        End If

        ' ProviderName is optional.
        nodeList = doc.GetElementsByTagName("ProviderName")
        Dim providerName As String = nodeList.Item(0).InnerText
        If Not providerName Is Nothing Then
            cspParameters.ProviderName = providerName
        End If

        ' ProviderType is optional.
        nodeList = doc.GetElementsByTagName("ProviderType")
        Dim providerType As String = nodeList.Item(0).InnerText
        If Not providerType Is Nothing Then
            cspParameters.ProviderType = Int32.Parse(providerType)
        End If
    Else
        Throw New ArgumentNullException("xmlString")
    End If
End Sub

Aplica-se a

Confira também