ISecurityEncodable.FromXml(SecurityElement) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
透過 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)
參數
用來重新建構安全性物件的 XML 編碼方式。
範例
下列程式代碼範例示範如何實作 FromXml 方法。 此程式代碼範例是針對 類別提供的較大範例的 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
備註
擴充安全性物件的自定義程式碼需要實 ToXml 作 和 FromXml 方法來讓對象成為安全性可編碼。