ReflectionPermission.ToXml 方法

定义

创建权限及其当前状态的 XML 编码。Creates an XML encoding of the permission and its current state.

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

返回

SecurityElement

权限的 XML 编码,包括任何状态信息。An XML encoding of the permission, including any state information.

示例

下面的代码示例演示方法的行为 ToXmlThe following code example shows the behavior of the ToXml method. 此示例是为类提供的更大示例的一部分 ReflectionPermissionThis example is part of a larger example provided for the ReflectionPermission class.

备注

此代码示例旨在显示方法的行为,而不是演示方法的用法。The code example is intended to show the behavior of the method, not to demonstrate its use. 通常,权限类的方法由安全基础结构使用;它们通常不在应用程序中使用。In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications.

private static void ToFromXmlDemo()
{
    ReflectionPermission memberAccessPerm = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
    ReflectionPermission restrictedMemberAccessPerm = new ReflectionPermission(PermissionState.None);
    restrictedMemberAccessPerm.FromXml(memberAccessPerm.ToXml());
    Console.WriteLine("Result of ToFromXml = " +
        restrictedMemberAccessPerm.ToString());
}
    Private Shared Sub ToFromXmlDemo()
        Dim memberAccessPerm As New ReflectionPermission(ReflectionPermissionFlag.MemberAccess)
        Dim restrictedMemberAccessPerm As New ReflectionPermission(PermissionState.None)
        restrictedMemberAccessPerm.FromXml(memberAccessPerm.ToXml())
        Console.WriteLine("Result of ToFromXml = " + restrictedMemberAccessPerm.ToString())

    End Sub
End Class

适用于