ToXml() public method

public ToXml ( ) : SecurityElement
return SecurityElement
		public void TypeInformation () 
		{
			ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.TypeInformation);
			Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.AreEqual ("TypeInformation", (se.Attributes ["Flags"] as string), "ToXml-Flags=TypeInformation");
		}
		public void MemberAccess () 
		{
			ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.MemberAccess);
			Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.AreEqual ("MemberAccess", (se.Attributes ["Flags"] as string), "ToXml-Flags=MemberAccess");
		}
		public void MemberAccess () 
		{
			ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.MemberAccess);
			Assert ("IsUnrestricted", !p.IsUnrestricted ());
			SecurityElement se = p.ToXml ();
			AssertEquals ("ToXml-Flags=MemberAccess", "MemberAccess", (se.Attributes ["Flags"] as string));
		}
		public void PermissionStateUnrestricted () 
		{
			ReflectionPermission p = new ReflectionPermission (PermissionState.Unrestricted);
			Assert.IsNotNull (p, "ReflectionPermission(PermissionState.Unrestricted)");
			Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
			ReflectionPermission copy = (ReflectionPermission) p.Copy ();
			Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
		}
		public void PermissionStateUnrestricted () 
		{
			ReflectionPermission p = new ReflectionPermission (PermissionState.Unrestricted);
			AssertNotNull ("ReflectionPermission(PermissionState.Unrestricted)", p);
			Assert ("IsUnrestricted", p.IsUnrestricted ());
			ReflectionPermission copy = (ReflectionPermission) p.Copy ();
			AssertEquals ("Copy.IsUnrestricted", p.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = p.ToXml ();
			AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string));
		}
		public void PermissionStateNone ()
		{
			ReflectionPermission p = new ReflectionPermission (PermissionState.None);
			Assert.IsNotNull (p, "ReflectionPermission(PermissionState.None)");
			Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
			ReflectionPermission copy = (ReflectionPermission) p.Copy ();
			Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version");
		}
		public void PermissionStateNone () 
		{
			ReflectionPermission p = new ReflectionPermission (PermissionState.None);
			AssertNotNull ("ReflectionPermission(PermissionState.None)", p);
			Assert ("IsUnrestricted", !p.IsUnrestricted ());
			ReflectionPermission copy = (ReflectionPermission) p.Copy ();
			AssertEquals ("Copy.IsUnrestricted", p.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = p.ToXml ();
			Assert ("ToXml-class", (se.Attributes ["class"] as string).StartsWith (className));
			AssertEquals ("ToXml-version", "1", (se.Attributes ["version"] as string));
		}
		public void AllFlags () 
		{
			ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.AllFlags);
			Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
		}
		public void ReflectionEmit () 
		{
			ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.ReflectionEmit);
			Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.AreEqual ("ReflectionEmit", (se.Attributes ["Flags"] as string), "ToXml-Flags=ReflectionEmit");
		}
		public void IntersectWithUnrestricted () 
		{
			ReflectionPermission p1 = new ReflectionPermission (PermissionState.Unrestricted);
			ReflectionPermission p2 = new ReflectionPermission (ReflectionPermissionFlag.MemberAccess);
			ReflectionPermission p3 = (ReflectionPermission) p1.Intersect (p2);
			Assert.IsTrue (!p3.IsUnrestricted (), "Unrestricted N P2 == P2");
			Assert.AreEqual (p2.ToXml ().ToString (), p3.ToXml ().ToString (), "Unrestricted N EP2 == EP2");
			p3 = (ReflectionPermission) p2.Intersect (p1);
			Assert.IsTrue (!p3.IsUnrestricted (), "P2 N Unrestricted == P2");
			Assert.AreEqual (p2.ToXml ().ToString (), p3.ToXml ().ToString (), "P2 N Unrestricted == P2");

			p2 = new ReflectionPermission (ReflectionPermissionFlag.NoFlags);
			p3 = (ReflectionPermission) p1.Intersect (p2);
			Assert.IsNull (p3, "Unrestricted N None == null");
		}
		public void UnionWithNull () 
		{
			ReflectionPermission p1 = new ReflectionPermission (ReflectionPermissionFlag.NoFlags);
			ReflectionPermission p2 = null;
			ReflectionPermission p3 = (ReflectionPermission) p1.Union (p2);
			Assert.AreEqual (p1.ToXml ().ToString (), p3.ToXml ().ToString (), "P1 U null == P1");
		}
		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");
		}
		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 void AllFlags () 
		{
			ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.AllFlags);
			Assert ("IsUnrestricted", p.IsUnrestricted ());
			SecurityElement se = p.ToXml ();
			AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string));
		}
		public void ReflectionEmit () 
		{
			ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.ReflectionEmit);
			Assert ("IsUnrestricted", !p.IsUnrestricted ());
			SecurityElement se = p.ToXml ();
			AssertEquals ("ToXml-Flags=ReflectionEmit", "ReflectionEmit", (se.Attributes ["Flags"] as string));
		}