Copy() public method

public Copy ( ) : IPermission
return IPermission
		public void PermissionStateUnrestricted () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted);
			AssertNotNull ("EnvironmentPermission(PermissionState.Unrestricted)", ep);
			Assert ("IsUnrestricted", ep.IsUnrestricted ());
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = ep.ToXml ();
			AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string));
		}
		public void PermissionStateUnrestricted () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted);
			Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.Unrestricted)");
			Assert.IsTrue (ep.IsUnrestricted (), "IsUnrestricted");
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = ep.ToXml ();
			Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
		}
		public void PermissionStateNone () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			AssertNotNull ("EnvironmentPermission(PermissionState.None)", ep);
			Assert ("IsUnrestricted", !ep.IsUnrestricted ());
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = ep.ToXml ();
			Assert ("ToXml-class", (se.Attributes ["class"] as string).StartsWith (className));
			AssertEquals ("ToXml-version", "1", (se.Attributes ["version"] as string));
		}
Example #4
0
        /// <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)
        {
            EnvironmentPermission environmentPermission = this.Cast(target);

            if (environmentPermission == null)
            {
                return(null);
            }
            if (this.IsUnrestricted())
            {
                return(environmentPermission.Copy());
            }
            if (environmentPermission.IsUnrestricted())
            {
                return(this.Copy());
            }
            int num = 0;
            EnvironmentPermission environmentPermission2 = new EnvironmentPermission(PermissionState.None);
            string pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Read);

            if (pathList != null)
            {
                string[] array = pathList.Split(new char[]
                {
                    ';'
                });
                foreach (string text in array)
                {
                    if (this.readList.Contains(text))
                    {
                        environmentPermission2.AddPathList(EnvironmentPermissionAccess.Read, text);
                        num++;
                    }
                }
            }
            string pathList2 = environmentPermission.GetPathList(EnvironmentPermissionAccess.Write);

            if (pathList2 != null)
            {
                string[] array3 = pathList2.Split(new char[]
                {
                    ';'
                });
                foreach (string text2 in array3)
                {
                    if (this.writeList.Contains(text2))
                    {
                        environmentPermission2.AddPathList(EnvironmentPermissionAccess.Write, text2);
                        num++;
                    }
                }
            }
            return((num <= 0) ? null : environmentPermission2);
        }
		public void PermissionStateNone () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.None)");
			Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted");
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = ep.ToXml ();
			Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version");
		}
        public override IPermission Intersect(IPermission target)
        {
            EnvironmentPermission ep = Cast(target);

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

            if (IsUnrestricted())
            {
                return(ep.Copy());
            }
            if (ep.IsUnrestricted())
            {
                return(Copy());
            }

            int n = 0;
            EnvironmentPermission result = new EnvironmentPermission(PermissionState.None);
            string readTarget            = ep.GetPathList(EnvironmentPermissionAccess.Read);

            if (readTarget != null)
            {
                string[] targets = readTarget.Split(';');
                foreach (string t in targets)
                {
                    if (readList.Contains(t))
                    {
                        result.AddPathList(EnvironmentPermissionAccess.Read, t);
                        n++;
                    }
                }
            }

            string writeTarget = ep.GetPathList(EnvironmentPermissionAccess.Write);

            if (writeTarget != null)
            {
                string[] targets = writeTarget.Split(';');
                foreach (string t in targets)
                {
                    if (writeList.Contains(t))
                    {
                        result.AddPathList(EnvironmentPermissionAccess.Write, t);
                        n++;
                    }
                }
            }
            return((n > 0) ? result : null);
        }