AsymmetricAlgorithm.FromXmlString(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当在派生类中重写时,从 XML 字符串重新构造 AsymmetricAlgorithm 对象。 否则,将引发 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)
参数
- xmlString
- String
用于重新构造 AsymmetricAlgorithm 对象的 XML 字符串。
示例
下面的代码示例演示如何实现 FromXmlString 方法来分析指定的 XML 字符串以填充当前 CspParameters 对象。 此代码示例是为 AsymmetricAlgorithm 类提供的一个更大示例的一部分。
// 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