UIPermission.FromXml(SecurityElement) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
透過 XML 編碼,重新建構具有指定狀態的權限。
public:
override void FromXml(System::Security::SecurityElement ^ esd);
public override void FromXml (System.Security.SecurityElement esd);
override this.FromXml : System.Security.SecurityElement -> unit
Public Overrides Sub FromXml (esd As SecurityElement)
參數
- esd
- SecurityElement
用以重新建構權限的 XML 編碼方式。
例外狀況
esd
參數為 null
。
範例
下列程式碼範例顯示 方法的行為 FromXml 。 這個範例是提供給 類別之較大範例的 UIPermission 一部分。
注意
程式碼範例旨在顯示 方法的行為,而不是示範其用法。 一般而言,安全性基礎結構會使用許可權類別的方法;它們通常不會用於應用程式。
// ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a
// permission with the specified state from the XML encoding.
void ToFromXmlDemo()
{
Console::WriteLine("\n********************** To/From XML() Demo *********************\n");
UIPermission ^ uiPerm1 = gcnew UIPermission(UIPermissionWindow::SafeTopLevelWindows);
UIPermission ^ uiPerm2 = gcnew UIPermission(PermissionState::None);
uiPerm2->FromXml(uiPerm1->ToXml());
bool result = uiPerm2->Equals(uiPerm1);
if (result)
Console::WriteLine("Result of ToFromXml = " + uiPerm2->ToString());
else
{
Console::WriteLine(uiPerm2->ToString());
Console::WriteLine(uiPerm1->ToString());
}
}
// ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a
// permission with the specified state from the XML encoding.
private static void ToFromXmlDemo()
{
UIPermission uiPerm1 = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);
UIPermission uiPerm2 = new UIPermission(PermissionState.None);
uiPerm2.FromXml(uiPerm1.ToXml());
bool result = uiPerm2.Equals(uiPerm1);
if (result)
{
Console.WriteLine("Result of ToFromXml = " + uiPerm2.ToString());
}
else
{
Console.WriteLine(uiPerm2.ToString());
Console.WriteLine(uiPerm1.ToString());
}
}
' ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a
' permission with the specified state from the XML encoding.
Private Shared Sub ToFromXmlDemo()
Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows)
Dim uiPerm2 As New UIPermission(PermissionState.None)
uiPerm2.FromXml(uiPerm1.ToXml())
Dim result As Boolean = uiPerm2.Equals(uiPerm1)
If result Then
Console.WriteLine("Result of ToFromXml = " + uiPerm2.ToString())
Else
Console.WriteLine(uiPerm2.ToString())
Console.WriteLine(uiPerm1.ToString())
End If
End Sub
End Class