UIPermission.FromXml(SecurityElement) Metoda

Definicja

Rekonstruuje uprawnienie o określonym stanie z kodowania 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)

Parametry

esd
SecurityElement

Kodowanie XML używane do odtworzenia uprawnienia.

Wyjątki

Parametr esd to null.

Parametr esd nie jest prawidłowym elementem uprawnień.

-lub-

Numer esd wersji parametru jest nieprawidłowy.

Przykłady

Poniższy przykład kodu przedstawia zachowanie FromXml metody. Ten przykład jest częścią większego przykładu udostępnionego UIPermission dla klasy.

Uwaga

Przykładowy kod ma na celu pokazanie zachowania metody, a nie zademonstrowania jej użycia. Ogólnie rzecz biorąc, metody klas uprawnień są używane przez infrastrukturę zabezpieczeń; nie są one zwykle używane w aplikacjach.


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

Dotyczy