AsymmetricAlgorithm.FromXmlString(String) Methode

Definition

Stellt beim Überschreiben in einer abgeleiteten Klasse ein AsymmetricAlgorithm-Objekt aus einer XML-Zeichenfolge wieder her. Löst andernfalls eine NotImplementedException aus.

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)

Parameter

xmlString
String

Die XML-Zeichenfolge zur Wiederherstellung des AsymmetricAlgorithm-Objekts.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die FromXmlString -Methode implementiert wird, um die angegebene XML-Zeichenfolge zu analysieren, um das aktuelle Objekt aufzufüllen CspParameters . Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die AsymmetricAlgorithm-Klasse bereitgestellt wird.

    // 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

Gilt für:

Weitere Informationen