Export (0) Print
Expand All

SecurityPermission.FromXml Method

Reconstructs a permission with a specified state from an XML encoding.

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

public override void FromXml(
	SecurityElement esd
)

Parameters

esd
Type: System.Security.SecurityElement

The XML encoding to use to reconstruct the permission.

Implements

ISecurityEncodable.FromXml(SecurityElement)

ExceptionCondition
ArgumentNullException

The esd parameter is null.

ArgumentException

The esd parameter is not a valid permission element.

-or-

The esd parameter's version number is not supported.

The following code example is intended to show the behavior of the FromXml method, not to demonstrate its use. In general, the methods of permission classes are used by the security infrastructure and are not intended for use in applications. However, the following code example shows how the method performs if you execute the method from your code. For the complete code example, see the SecurityPermission class.

private bool ToFromXmlDemo()
{

    bool returnValue = true;

    SecurityPermissionFlag security1;
    SecurityPermission securityPerm1,securityPerm2;
    SecurityGenerator SecurityGen1 = new SecurityGenerator();
    SecurityGenerator SecurityGen2 = new SecurityGenerator();
    SecurityGen1.ResetIndex();
    while(SecurityGen1.GetSecurityFlag( out security1 ))
    {
        securityPerm1 = new SecurityPermission(security1);
        Console.WriteLine("********************************************************\n");
        SecurityGen2.ResetIndex();
        try
        {
            securityPerm2= new SecurityPermission(PermissionState.None);
            securityPerm2.FromXml(securityPerm1.ToXml());
            Console.WriteLine("Result of ToFromXml = " +
                securityPerm2.ToString());

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

    return returnValue;

}

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft