Copy() public method

public Copy ( ) : IPermission
return IPermission
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Intersect(IPermission target)
        {
            ReflectionPermission reflectionPermission = this.Cast(target);

            if (reflectionPermission == null)
            {
                return(null);
            }
            if (this.IsUnrestricted())
            {
                if (reflectionPermission.Flags == ReflectionPermissionFlag.NoFlags)
                {
                    return(null);
                }
                return(reflectionPermission.Copy());
            }
            else
            {
                if (!reflectionPermission.IsUnrestricted())
                {
                    ReflectionPermission reflectionPermission2 = (ReflectionPermission)reflectionPermission.Copy();
                    reflectionPermission2.Flags &= this.flags;
                    return((reflectionPermission2.Flags != ReflectionPermissionFlag.NoFlags) ? reflectionPermission2 : null);
                }
                if (this.flags == ReflectionPermissionFlag.NoFlags)
                {
                    return(null);
                }
                return(this.Copy());
            }
        }
		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));
		}
Example #6
0
        public override IPermission Intersect(IPermission target)
        {
            ReflectionPermission rp = Cast(target);

            if (rp == null)
            {
                return(null);
            }

            if (IsUnrestricted())
            {
                if (rp.Flags == ReflectionPermissionFlag.NoFlags)
                {
                    return(null);
                }
                else
                {
                    return(rp.Copy());
                }
            }
            if (rp.IsUnrestricted())
            {
                if (flags == ReflectionPermissionFlag.NoFlags)
                {
                    return(null);
                }
                else
                {
                    return(Copy());
                }
            }

            ReflectionPermission p = (ReflectionPermission)rp.Copy();

            p.Flags &= flags;
            return((p.Flags == ReflectionPermissionFlag.NoFlags) ? null : p);
        }
        /// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <param name="other">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Union(IPermission other)
        {
            ReflectionPermission reflectionPermission = this.Cast(other);

            if (other == null)
            {
                return(this.Copy());
            }
            if (this.IsUnrestricted() || reflectionPermission.IsUnrestricted())
            {
                return(new ReflectionPermission(PermissionState.Unrestricted));
            }
            ReflectionPermission reflectionPermission2 = (ReflectionPermission)reflectionPermission.Copy();

            reflectionPermission2.Flags |= this.flags;
            return(reflectionPermission2);
        }
Example #8
0
        public override IPermission Union(IPermission other)
        {
            ReflectionPermission rp = Cast(other);

            if (other == null)
            {
                return(Copy());
            }

            if (IsUnrestricted() || rp.IsUnrestricted())
            {
                return(new ReflectionPermission(PermissionState.Unrestricted));
            }

            ReflectionPermission p = (ReflectionPermission)rp.Copy();

            p.Flags |= flags;
            return(p);
        }
		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");
		}