Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ReflectionPermission.ToXml Method

Creates an XML encoding of the permission and its current state.

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

public override SecurityElement ToXml ()
public SecurityElement ToXml ()
public override function ToXml () : SecurityElement

Return Value

An XML encoding of the permission, including any state information.

private bool ToFromXmlDemo()
{

    bool returnValue = true;

    ReflectionPermissionFlag reflection1;
    ReflectionPermission reflectionPerm1, reflectionPerm2;
    ReflectionGenerator reflectionGen1 = new ReflectionGenerator();
    ReflectionGenerator reflectionGen2 = new ReflectionGenerator();
    reflectionGen1.ResetIndex();
    while (reflectionGen1.CreateReflection(out reflection1))
    {
        reflectionPerm1 = new ReflectionPermission(reflection1);
        Console.WriteLine("********************************************************\n");
        reflectionGen2.ResetIndex();
        try
        {
            reflectionPerm2 = new ReflectionPermission(PermissionState.None);
            reflectionPerm2.FromXml(reflectionPerm1.ToXml());
            Console.WriteLine("Result of ToFromXml = " +
                reflectionPerm2.ToString());

        }
        catch (Exception e)
        {
            Console.WriteLine("ToFromXml failed :" + reflectionPerm1.ToString() + e);
            continue;
        }
    }

    return returnValue;

}

private boolean ToFromXmlDemo() 
{
    boolean returnValue = true;
    ReflectionPermissionFlag reflection1[] = 
        new ReflectionPermissionFlag[1];
    ReflectionPermission reflectionPerm1[] = 
        new ReflectionPermission[1];
    ReflectionPermission reflectionPerm2[] = 
        new ReflectionPermission[1];
    ReflectionGenerator reflectionGen1 =  
        new ReflectionGenerator();
    ReflectionGenerator reflectionGen2 =  
        new ReflectionGenerator();
    reflectionGen1.ResetIndex();
    while(reflectionGen1.CreateReflection(reflectionPerm1, reflection1)) {
        if (reflectionPerm1[0] == null) {
            continue ;
        }
        Console.WriteLine("**************************************" 
            + "******************\n");
        reflectionGen2.ResetIndex();
        try {
            reflectionPerm2[0] = 
                new ReflectionPermission(PermissionState.None);
            reflectionPerm2[0].FromXml(reflectionPerm1[0].ToXml());
            Console.WriteLine(("Result of ToFromXml = " 
                + reflectionPerm2[0].ToString()));
        }
        catch(System.Exception e) {
            Console.WriteLine(("ToFromXml failed :" 
                + reflectionPerm1[0].ToString() + e));
            continue ;
        }
    }
    return returnValue ;
} //ToFromXmlDemo    

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft