Export (0) Print
Expand All

ReflectionPermission.FromXml Method

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

[Visual Basic]
Overrides Public Sub FromXml( _
   ByVal esd As SecurityElement _
) Implements ISecurityEncodable.FromXml
[C#]
public override void FromXml(
 SecurityElement esd
);
[C++]
public: void FromXml(
 SecurityElement* esd
);
[JScript]
public override function FromXml(
   esd : SecurityElement
);

Parameters

esd
The XML encoding to use to reconstruct the permission.

Implements

ISecurityEncodable.FromXml

Exceptions

Exception Type Condition
ArgumentNullException The esd parameter is a null reference (Nothing in Visual Basic).
ArgumentException The esd parameter is not a valid permission element.

-or-

The esd parameter's version number is not valid.

Example

[Visual Basic] 
' 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 Function ToFromXmlDemo() As Boolean

    Dim returnValue As Boolean = True

    Dim reflection1 As ReflectionPermissionFlag
    Dim reflectionPerm1, reflectionPerm2 As ReflectionPermission
    Dim reflectionGen1 As New ReflectionGenerator()
    Dim reflectionGen2 As New ReflectionGenerator()
    reflectionGen1.ResetIndex()
    While reflectionGen1.CreateReflection(reflectionPerm1, reflection1)
        If reflectionPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("********************************************************" & ControlChars.Lf)
        reflectionGen2.ResetIndex()
        Try
            reflectionPerm2 = New ReflectionPermission(PermissionState.None)
            reflectionPerm2.FromXml(reflectionPerm1.ToXml())
            Console.WriteLine(("Result of ToFromXml = " & reflectionPerm2.ToString()))

        Catch e As Exception
            Console.WriteLine(("ToFromXml failed :" & reflectionPerm1.ToString() & e.ToString()))
            GoTo ContinueWhile1
        End Try
ContinueWhile1:
    End While

    Return returnValue
End Function 'ToFromXmlDemo


[C#] 
// 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 bool ToFromXmlDemo()
{

    bool returnValue = true;

    ReflectionPermissionFlag reflection1;
    ReflectionPermission reflectionPerm1,reflectionPerm2;
    ReflectionGenerator reflectionGen1 = new ReflectionGenerator();
    ReflectionGenerator reflectionGen2 = new ReflectionGenerator();
    reflectionGen1.ResetIndex();
    while(reflectionGen1.CreateReflection(out reflectionPerm1, out reflection1)) 
    {
        if(reflectionPerm1 == null) continue;
        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;

}

[C++] 
// 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:
bool ToFromXmlDemo() {

   bool returnValue = true;

   ReflectionPermissionFlag reflection1;
   ReflectionPermission* reflectionPerm1, *reflectionPerm2;
   ReflectionGenerator* reflectionGen1 = new ReflectionGenerator();
   ReflectionGenerator* reflectionGen2 = new ReflectionGenerator();
   reflectionGen1->ResetIndex();
   while(reflectionGen1->CreateReflection(&reflectionPerm1, &reflection1)) {
      if (reflectionPerm1 == 0) continue;
      Console::WriteLine(S"********************************************************\n");
      reflectionGen2->ResetIndex();
      try {
         reflectionPerm2 = new ReflectionPermission(PermissionState::None);
         reflectionPerm2->FromXml(reflectionPerm1->ToXml());
         Console::WriteLine(S"Result of ToFromXml = {0}", reflectionPerm2);

      } catch (Exception* e) {
         Console::WriteLine(S"ToFromXml failed : {0}{1}", reflectionPerm1, e);
         continue;
      }
   }

   return returnValue;

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

ReflectionPermission Class | ReflectionPermission Members | System.Security.Permissions Namespace

Show:
© 2014 Microsoft