Copy() public method

public Copy ( ) : IPermission
return IPermission
        public override IPermission Union(IPermission target)
        {
            ZoneIdentityPermission zip = Cast(target);

            if (zip == null)
            {
                return((zone == SecurityZone.NoZone) ? null : Copy());
            }

            if (zone == zip.zone || zip.zone == SecurityZone.NoZone)
            {
                return(Copy());
            }

            if (zone == SecurityZone.NoZone)
            {
                return(zip.Copy());
            }
#if NET_2_0
            throw new ArgumentException(Locale.GetText(
                                            "Union impossible"));
#else
            return(null);
#endif
        }
Beispiel #2
0
        /// <include file='doc\ZoneIdentityPermission.uex' path='docs/doc[@for="ZoneIdentityPermission.Union"]/*' />
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.m_zone != SecurityZone.NoZone ? this.Copy() : null);
            }
            else if (!VerifyType(target))
            {
                throw new
                      ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
                          );
            }

            ZoneIdentityPermission operand = (ZoneIdentityPermission)target;

            if (this.m_zone == operand.m_zone || operand.m_zone == SecurityZone.NoZone)
            {
                return(this.Copy());
            }
            else if (this.m_zone == SecurityZone.NoZone)
            {
                return(operand.Copy());
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        /// <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="target">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="target" /> parameter is not null and is not of the same type as the current permission. -or-The two permissions are not equal and the current permission does not represent the <see cref="F:System.Security.SecurityZone.NoZone" /> security zone.</exception>
        public override IPermission Union(IPermission target)
        {
            ZoneIdentityPermission zoneIdentityPermission = this.Cast(target);

            if (zoneIdentityPermission == null)
            {
                IPermission result;
                if (this.zone == SecurityZone.NoZone)
                {
                    IPermission permission = null;
                    result = permission;
                }
                else
                {
                    result = this.Copy();
                }
                return(result);
            }
            if (this.zone == zoneIdentityPermission.zone || zoneIdentityPermission.zone == SecurityZone.NoZone)
            {
                return(this.Copy());
            }
            if (this.zone == SecurityZone.NoZone)
            {
                return(zoneIdentityPermission.Copy());
            }
            throw new ArgumentException(Locale.GetText("Union impossible"));
        }
		private ZoneIdentityPermission BasicTestZone (SecurityZone zone, bool special)
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (zone);
			Assert.AreEqual (zone, zip.SecurityZone, "SecurityZone");
			
			ZoneIdentityPermission copy = (ZoneIdentityPermission) zip.Copy ();
			Assert.IsTrue (Same (zip, copy), "Equals-Copy");
			Assert.IsTrue (zip.IsSubsetOf (copy), "IsSubset-1");
			Assert.IsTrue (copy.IsSubsetOf (zip), "IsSubset-2");
			if (special) {
				Assert.IsFalse (zip.IsSubsetOf (null), "IsSubset-Null");
			}
			
			IPermission intersect = zip.Intersect (copy);
			if (special) {
				Assert.IsTrue (intersect.IsSubsetOf (zip), "IsSubset-3");
				Assert.IsFalse (Object.ReferenceEquals (zip, intersect), "!ReferenceEquals1");
				Assert.IsTrue (intersect.IsSubsetOf (copy), "IsSubset-4");
				Assert.IsFalse (Object.ReferenceEquals (copy, intersect), "!ReferenceEquals2");
			}

			Assert.IsNull (zip.Intersect (null), "Intersect with null");

			intersect = zip.Intersect (new ZoneIdentityPermission (PermissionState.None));
			Assert.IsNull (intersect, "Intersect with PS.None");

			// note: can't be tested with PermissionState.Unrestricted

			// XML roundtrip
			SecurityElement se = zip.ToXml ();
			copy.FromXml (se);
			Assert.IsTrue (Same (zip, copy), "Equals-Xml");

			return zip;
		}