public void FromXml() { ReflectionPermission p = new ReflectionPermission(PermissionState.None); SecurityElement se = p.ToXml(); Assert.IsNotNull(se, "ToXml()"); ReflectionPermission p2 = (ReflectionPermission)p.Copy(); p2.FromXml(se); Assert.AreEqual(ReflectionPermissionFlag.NoFlags, p2.Flags, "FromXml-None"); string className = (string)se.Attributes ["class"]; string version = (string)se.Attributes ["version"]; SecurityElement se2 = new SecurityElement(se.Tag); se2.AddAttribute("class", className); se2.AddAttribute("version", version); se2.AddAttribute("Flags", "TypeInformation"); p2.FromXml(se2); Assert.AreEqual(ReflectionPermissionFlag.TypeInformation, p2.Flags, "FromXml-TypeInformation"); se2 = new SecurityElement(se.Tag); se2.AddAttribute("class", className); se2.AddAttribute("version", version); se2.AddAttribute("Flags", "MemberAccess"); p2.FromXml(se2); Assert.AreEqual(ReflectionPermissionFlag.MemberAccess, p2.Flags, "FromXml-MemberAccess"); se2 = new SecurityElement(se.Tag); se2.AddAttribute("class", className); se2.AddAttribute("version", version); se2.AddAttribute("Flags", "ReflectionEmit"); p2.FromXml(se2); Assert.AreEqual(ReflectionPermissionFlag.ReflectionEmit, p2.Flags, "FromXml-ReflectionEmit"); se = p.ToXml(); se.AddAttribute("Unrestricted", "true"); p2.FromXml(se); Assert.IsTrue(p2.IsUnrestricted(), "FromXml-Unrestricted"); Assert.AreEqual(ReflectionPermissionFlag.AllFlags, p2.Flags, "FromXml-AllFlags"); }
//</Snippet5> // ToXml creates an XML encoding of the permission and its current state; // FromXml reconstructs a permission with the specified state from the XML encoding. //<Snippet6> private static void ToFromXmlDemo() { ReflectionPermission memberAccessPerm = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess); //<Snippet7> ReflectionPermission restrictedMemberAccessPerm = new ReflectionPermission(PermissionState.None); //</Snippet7> restrictedMemberAccessPerm.FromXml(memberAccessPerm.ToXml()); Console.WriteLine("Result of ToFromXml = " + restrictedMemberAccessPerm.ToString()); }
public void FromXmlWrongVersion() { ReflectionPermission p = new ReflectionPermission(PermissionState.None); SecurityElement se = p.ToXml(); // can't modify - so we create our own SecurityElement se2 = new SecurityElement(se.Tag, se.Text); se2.AddAttribute("class", se.Attribute("class")); se2.AddAttribute("version", "2"); p.FromXml(se2); }
public static void ReflectionPermissionCallMethods() { ReflectionPermission rp = new ReflectionPermission(new Permissions.PermissionState()); ReflectionPermission rp2 = new ReflectionPermission(new Permissions.ReflectionPermissionFlag()); IPermission ip = rp.Copy(); IPermission ip2 = rp.Intersect(ip); bool testbool = rp.IsSubsetOf(ip); testbool = rp.IsUnrestricted(); ip2 = rp.Union(ip); SecurityElement se = new SecurityElement(""); rp.FromXml(se); se = rp.ToXml(); }
public void FromXmlNull() { ReflectionPermission p = new ReflectionPermission(PermissionState.None); p.FromXml(null); }