UIPermission.ToXml Metodo

Definizione

Crea una codifica XML dell'autorizzazione e del relativo stato corrente.

public:
 override System::Security::SecurityElement ^ ToXml();
public override System.Security.SecurityElement ToXml ();
override this.ToXml : unit -> System.Security.SecurityElement
Public Overrides Function ToXml () As SecurityElement

Restituisce

SecurityElement

Codifica XML dell'autorizzazione, che include le eventuali informazioni sullo stato.

Esempio

Nell'esempio ToXml di codice seguente viene illustrato il comportamento del metodo. Questo esempio fa parte di un esempio più grande fornito per la UIPermission classe.

Nota

L'esempio di codice è destinato a mostrare il comportamento del metodo, non per illustrarne l'uso. In generale, i metodi delle classi di autorizzazione vengono usati dall'infrastruttura di sicurezza; non vengono in genere usati nelle applicazioni.


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

Si applica a