UIPermission.FromXml(SecurityElement) 方法

定义

从 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

esd 参数不是有效的权限元素。

- 或 -

esd 参数的版本号无效。

示例

下面的代码示例演示 方法的行为 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

适用于