Copy() public method

public Copy ( ) : IPermission
return IPermission
		public void PermissionState_None ()
		{
			SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None);
			Assert.AreEqual (String.Empty, sip.Site, "Site");
			SecurityElement se = sip.ToXml ();
			// only class and version are present
			Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes");
			Assert.IsNull (se.Children, "Xml-Children");
			SiteIdentityPermission copy = (SiteIdentityPermission)sip.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (sip, copy), "ReferenceEquals");
		}
Example #2
0
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            SiteIdentityPermission permission = target as SiteIdentityPermission;

            if (permission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            if (this.m_unrestricted && permission.m_unrestricted)
            {
                return(new SiteIdentityPermission(PermissionState.None)
                {
                    m_unrestricted = true
                });
            }
            if (this.m_unrestricted)
            {
                return(permission.Copy());
            }
            if (permission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (((this.m_sites == null) || (permission.m_sites == null)) || ((this.m_sites.Length == 0) || (permission.m_sites.Length == 0)))
            {
                return(null);
            }
            List <SiteString> list = new List <SiteString>();

            foreach (SiteString str in this.m_sites)
            {
                foreach (SiteString str2 in permission.m_sites)
                {
                    SiteString item = str.Intersect(str2);
                    if (item != null)
                    {
                        list.Add(item);
                    }
                }
            }
            if (list.Count == 0)
            {
                return(null);
            }
            return(new SiteIdentityPermission(PermissionState.None)
            {
                m_sites = list.ToArray()
            });
        }
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            SiteIdentityPermission that = target as SiteIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            if (this.m_unrestricted && that.m_unrestricted)
            {
                SiteIdentityPermission res = new SiteIdentityPermission(PermissionState.None);
                res.m_unrestricted = true;
                return(res);
            }
            if (this.m_unrestricted)
            {
                return(that.Copy());
            }
            if (that.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_sites == null || that.m_sites == null || this.m_sites.Length == 0 || that.m_sites.Length == 0)
            {
                return(null);
            }
            List <SiteString> alSites = new List <SiteString>();

            foreach (SiteString ssThis in this.m_sites)
            {
                foreach (SiteString ssThat in that.m_sites)
                {
                    SiteString ssInt = (SiteString)ssThis.Intersect(ssThat);
                    if (ssInt != null)
                    {
                        alSites.Add(ssInt);
                    }
                }
            }
            if (alSites.Count == 0)
            {
                return(null);
            }
            SiteIdentityPermission result = new SiteIdentityPermission(PermissionState.None);

            result.m_sites = alSites.ToArray();
            return(result);
        }
		public void PermissionStateUnrestricted ()
		{
			// In 2.0 Unrestricted are permitted for identity permissions
			SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.Unrestricted);
			Assert.AreEqual (String.Empty, sip.Site, "Site");
			SecurityElement se = sip.ToXml ();
			Assert.AreEqual (3, se.Attributes.Count, "Xml-Attributes");
			Assert.IsNull (se.Children, "Xml-Children");
			SiteIdentityPermission copy = (SiteIdentityPermission)sip.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (sip, copy), "ReferenceEquals");
			// and they aren't equals to None
			Assert.IsFalse (sip.Equals (new SiteIdentityPermission (PermissionState.None)));
		}
Example #5
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 permissions are not equal and one is not a subset of the other.</exception>
        public override IPermission Union(IPermission target)
        {
            SiteIdentityPermission siteIdentityPermission = this.Cast(target);

            if (siteIdentityPermission == null || siteIdentityPermission.IsEmpty())
            {
                return(this.Copy());
            }
            if (this.IsEmpty())
            {
                return(siteIdentityPermission.Copy());
            }
            if (this.Match(siteIdentityPermission._site))
            {
                string site = (this._site.Length >= siteIdentityPermission._site.Length) ? siteIdentityPermission._site : this._site;
                return(new SiteIdentityPermission(site));
            }
            throw new ArgumentException(Locale.GetText("Cannot union two different sites."), "target");
        }
        public override IPermission Union(IPermission target)
        {
            SiteIdentityPermission sip = Cast(target);

            if ((sip == null) || sip.IsEmpty())
            {
                return(Copy());
            }
            if (IsEmpty())
            {
                return(sip.Copy());
            }

            if (Match(sip._site))
            {
                string s = ((_site.Length < sip._site.Length) ? _site : sip._site);
                return(new SiteIdentityPermission(s));
            }
            throw new ArgumentException(Locale.GetText(
                                            "Cannot union two different sites."), "target");
        }
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if ((this.m_sites == null || this.m_sites.Length == 0) && !this.m_unrestricted)
                {
                    return(null);
                }
                return(this.Copy());
            }
            SiteIdentityPermission that = target as SiteIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            if (this.m_unrestricted || that.m_unrestricted)
            {
                SiteIdentityPermission res = new SiteIdentityPermission(PermissionState.None);
                res.m_unrestricted = true;
                return(res);
            }
            if (this.m_sites == null || this.m_sites.Length == 0)
            {
                if (that.m_sites == null || that.m_sites.Length == 0)
                {
                    return(null);
                }
                return(that.Copy());
            }
            if (that.m_sites == null || that.m_sites.Length == 0)
            {
                return(this.Copy());
            }
            List <SiteString> alSites = new List <SiteString>();

            foreach (SiteString ssThis in this.m_sites)
            {
                alSites.Add(ssThis);
            }
            foreach (SiteString ssThat in that.m_sites)
            {
                bool bDupe = false;
                foreach (SiteString ss in alSites)
                {
                    if (ssThat.Equals(ss))
                    {
                        bDupe = true;
                        break;
                    }
                }
                if (!bDupe)
                {
                    alSites.Add(ssThat);
                }
            }
            SiteIdentityPermission result = new SiteIdentityPermission(PermissionState.None);

            result.m_sites = alSites.ToArray();
            return(result);
        }
        /// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary>
        /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns>
        /// <param name="target">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -这两个权限不相等,而且其中一个不是另一个的子集。</exception>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if ((this.m_sites == null || this.m_sites.Length == 0) && !this.m_unrestricted)
                {
                    return((IPermission)null);
                }
                return(this.Copy());
            }
            SiteIdentityPermission identityPermission = target as SiteIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            if (this.m_unrestricted || identityPermission.m_unrestricted)
            {
                return (IPermission) new SiteIdentityPermission(PermissionState.None)
                       {
                           m_unrestricted = true
                       }
            }
            ;
            if (this.m_sites == null || this.m_sites.Length == 0)
            {
                if (identityPermission.m_sites == null || identityPermission.m_sites.Length == 0)
                {
                    return((IPermission)null);
                }
                return(identityPermission.Copy());
            }
            if (identityPermission.m_sites == null || identityPermission.m_sites.Length == 0)
            {
                return(this.Copy());
            }
            List <SiteString> siteStringList = new List <SiteString>();

            foreach (SiteString mSite in this.m_sites)
            {
                siteStringList.Add(mSite);
            }
            foreach (SiteString mSite in identityPermission.m_sites)
            {
                bool flag = false;
                foreach (SiteString siteString in siteStringList)
                {
                    if (mSite.Equals((object)siteString))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    siteStringList.Add(mSite);
                }
            }
            return((IPermission) new SiteIdentityPermission(PermissionState.None)
            {
                m_sites = siteStringList.ToArray()
            });
        }
		public void Copy ()
		{
			SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None);
			foreach (string s in GoodSites)	{
				sip.Site = s;
				SiteIdentityPermission copy = (SiteIdentityPermission)sip.Copy ();
				Assert.AreEqual (s, copy.Site, s);
			}
		}
Example #10
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if (((this.m_sites == null) || (this.m_sites.Length == 0)) && !this.m_unrestricted)
                {
                    return(null);
                }
                return(this.Copy());
            }
            SiteIdentityPermission permission = target as SiteIdentityPermission;

            if (permission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            if (this.m_unrestricted || permission.m_unrestricted)
            {
                return(new SiteIdentityPermission(PermissionState.None)
                {
                    m_unrestricted = true
                });
            }
            if ((this.m_sites == null) || (this.m_sites.Length == 0))
            {
                if ((permission.m_sites != null) && (permission.m_sites.Length != 0))
                {
                    return(permission.Copy());
                }
                return(null);
            }
            if ((permission.m_sites == null) || (permission.m_sites.Length == 0))
            {
                return(this.Copy());
            }
            List <SiteString> list = new List <SiteString>();

            foreach (SiteString str in this.m_sites)
            {
                list.Add(str);
            }
            foreach (SiteString str2 in permission.m_sites)
            {
                bool flag = false;
                foreach (SiteString str3 in list)
                {
                    if (str2.Equals(str3))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    list.Add(str2);
                }
            }
            return(new SiteIdentityPermission(PermissionState.None)
            {
                m_sites = list.ToArray()
            });
        }