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>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is <see langword="null" /> if the intersection is empty.</returns>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception>
        // Token: 0x060026D9 RID: 9945 RVA: 0x0008CEF8 File Offset: 0x0008B0F8
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            PublisherIdentityPermission publisherIdentityPermission = target as PublisherIdentityPermission;

            if (publisherIdentityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
                {
                    base.GetType().FullName
                }));
            }
            if (this.m_unrestricted && publisherIdentityPermission.m_unrestricted)
            {
                return(new PublisherIdentityPermission(PermissionState.None)
                {
                    m_unrestricted = true
                });
            }
            if (this.m_unrestricted)
            {
                return(publisherIdentityPermission.Copy());
            }
            if (publisherIdentityPermission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_certs == null || publisherIdentityPermission.m_certs == null || this.m_certs.Length == 0 || publisherIdentityPermission.m_certs.Length == 0)
            {
                return(null);
            }
            ArrayList arrayList = new ArrayList();

            foreach (X509Certificate x509Certificate in this.m_certs)
            {
                foreach (X509Certificate other in publisherIdentityPermission.m_certs)
                {
                    if (x509Certificate.Equals(other))
                    {
                        arrayList.Add(new X509Certificate(x509Certificate));
                    }
                }
            }
            if (arrayList.Count == 0)
            {
                return(null);
            }
            return(new PublisherIdentityPermission(PermissionState.None)
            {
                m_certs = (X509Certificate[])arrayList.ToArray(typeof(X509Certificate))
            });
        }
        /// <summary>创建并返回一个权限,该权限是当前权限和指定权限的交集。</summary>
        /// <returns>一个新权限,它表示当前权限与指定权限的交集。如果交集为空,则此新权限为 null。</returns>
        /// <param name="target">要与当前权限相交的权限。它必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return((IPermission)null);
            }
            PublisherIdentityPermission identityPermission = target as PublisherIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            if (this.m_unrestricted && identityPermission.m_unrestricted)
            {
                return (IPermission) new PublisherIdentityPermission(PermissionState.None)
                       {
                           m_unrestricted = true
                       }
            }
            ;
            if (this.m_unrestricted)
            {
                return(identityPermission.Copy());
            }
            if (identityPermission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_certs == null || identityPermission.m_certs == null || (this.m_certs.Length == 0 || identityPermission.m_certs.Length == 0))
            {
                return((IPermission)null);
            }
            ArrayList arrayList = new ArrayList();

            foreach (X509Certificate mCert1 in this.m_certs)
            {
                foreach (X509Certificate mCert2 in identityPermission.m_certs)
                {
                    if (mCert1.Equals(mCert2))
                    {
                        arrayList.Add((object)new X509Certificate(mCert1));
                    }
                }
            }
            if (arrayList.Count == 0)
            {
                return((IPermission)null);
            }
            return((IPermission) new PublisherIdentityPermission(PermissionState.None)
            {
                m_certs = (X509Certificate[])arrayList.ToArray(typeof(X509Certificate))
            });
        }
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            PublisherIdentityPermission that = target as PublisherIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            if (this.m_unrestricted && that.m_unrestricted)
            {
                PublisherIdentityPermission res = new PublisherIdentityPermission(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_certs == null || that.m_certs == null || this.m_certs.Length == 0 || that.m_certs.Length == 0)
            {
                return(null);
            }
            ArrayList alCerts = new ArrayList();

            foreach (X509Certificate certThis in this.m_certs)
            {
                foreach (X509Certificate certThat in that.m_certs)
                {
                    if (certThis.Equals(certThat))
                    {
                        alCerts.Add(new X509Certificate(certThis));
                    }
                }
            }
            if (alCerts.Count == 0)
            {
                return(null);
            }
            PublisherIdentityPermission result = new PublisherIdentityPermission(PermissionState.None);

            result.m_certs = (X509Certificate[])alCerts.ToArray(typeof(X509Certificate));
            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_certs == null || this.m_certs.Length == 0) && !this.m_unrestricted)
                {
                    return((IPermission)null);
                }
                return(this.Copy());
            }
            PublisherIdentityPermission identityPermission = target as PublisherIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            if (this.m_unrestricted || identityPermission.m_unrestricted)
            {
                return (IPermission) new PublisherIdentityPermission(PermissionState.None)
                       {
                           m_unrestricted = true
                       }
            }
            ;
            if (this.m_certs == null || this.m_certs.Length == 0)
            {
                if (identityPermission.m_certs == null || identityPermission.m_certs.Length == 0)
                {
                    return((IPermission)null);
                }
                return(identityPermission.Copy());
            }
            if (identityPermission.m_certs == null || identityPermission.m_certs.Length == 0)
            {
                return(this.Copy());
            }
            ArrayList arrayList = new ArrayList();

            foreach (X509Certificate mCert in this.m_certs)
            {
                arrayList.Add((object)mCert);
            }
            foreach (X509Certificate mCert in identityPermission.m_certs)
            {
                bool flag = false;
                foreach (X509Certificate other in arrayList)
                {
                    if (mCert.Equals(other))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    arrayList.Add((object)mCert);
                }
            }
            return((IPermission) new PublisherIdentityPermission(PermissionState.None)
            {
                m_certs = (X509Certificate[])arrayList.ToArray(typeof(X509Certificate))
            });
        }
		public void PermissionStateNone () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			Assert.IsNotNull (p, "PublisherIdentityPermission(PermissionState.None)");
			PublisherIdentityPermission copy = (PublisherIdentityPermission) p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert.IsTrue (se.Attribute ("class").StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", se.Attribute("version"), "ToXml-version");
			Assert.IsNull (se.Attribute("Unrestricted"), "ToXml-Unrestricted");
			Assert.IsNull (p.Certificate, "Certificate==null");
		}
		public void PermissionStateUnrestricted ()
		{
			// In 2.0 Unrestricted are permitted for identity permissions
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.Unrestricted);
			Assert.IsNotNull (p, "PublisherIdentityPermission(PermissionState.None)");
			PublisherIdentityPermission copy = (PublisherIdentityPermission)p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert.IsTrue (se.Attribute ("class").StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", se.Attribute("version"), "ToXml-version");
			Assert.AreEqual ("true", se.Attribute("Unrestricted"), "ToXml-Unrestricted");
			Assert.IsNull (p.Certificate, "Certificate==null");
			// and they aren't equals to None
			Assert.IsTrue (!p.Equals (new PublisherIdentityPermission (PermissionState.None)));
		}
 /// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
 /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
 /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
 /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. -or-The two permissions are not equal.</exception>
 // Token: 0x060026DA RID: 9946 RVA: 0x0008D02C File Offset: 0x0008B22C
 public override IPermission Union(IPermission target)
 {
     if (target == null)
     {
         if ((this.m_certs == null || this.m_certs.Length == 0) && !this.m_unrestricted)
         {
             return(null);
         }
         return(this.Copy());
     }
     else
     {
         PublisherIdentityPermission publisherIdentityPermission = target as PublisherIdentityPermission;
         if (publisherIdentityPermission == null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
             {
                 base.GetType().FullName
             }));
         }
         if (this.m_unrestricted || publisherIdentityPermission.m_unrestricted)
         {
             return(new PublisherIdentityPermission(PermissionState.None)
             {
                 m_unrestricted = true
             });
         }
         if (this.m_certs == null || this.m_certs.Length == 0)
         {
             if (publisherIdentityPermission.m_certs == null || publisherIdentityPermission.m_certs.Length == 0)
             {
                 return(null);
             }
             return(publisherIdentityPermission.Copy());
         }
         else
         {
             if (publisherIdentityPermission.m_certs == null || publisherIdentityPermission.m_certs.Length == 0)
             {
                 return(this.Copy());
             }
             ArrayList arrayList = new ArrayList();
             foreach (X509Certificate value in this.m_certs)
             {
                 arrayList.Add(value);
             }
             foreach (X509Certificate x509Certificate in publisherIdentityPermission.m_certs)
             {
                 bool flag = false;
                 foreach (object obj in arrayList)
                 {
                     X509Certificate other = (X509Certificate)obj;
                     if (x509Certificate.Equals(other))
                     {
                         flag = true;
                         break;
                     }
                 }
                 if (!flag)
                 {
                     arrayList.Add(x509Certificate);
                 }
             }
             return(new PublisherIdentityPermission(PermissionState.None)
             {
                 m_certs = (X509Certificate[])arrayList.ToArray(typeof(X509Certificate))
             });
         }
     }
 }
Example #8
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if (((this.m_certs == null) || (this.m_certs.Length == 0)) && !this.m_unrestricted)
                {
                    return(null);
                }
                return(this.Copy());
            }
            PublisherIdentityPermission permission = target as PublisherIdentityPermission;

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

            foreach (X509Certificate certificate in this.m_certs)
            {
                list.Add(certificate);
            }
            foreach (X509Certificate certificate2 in permission.m_certs)
            {
                bool flag = false;
                foreach (X509Certificate certificate3 in list)
                {
                    if (certificate2.Equals(certificate3))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    list.Add(certificate2);
                }
            }
            return(new PublisherIdentityPermission(PermissionState.None)
            {
                m_certs = (X509Certificate[])list.ToArray(typeof(X509Certificate))
            });
        }
		public void PermissionStateNone () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			AssertNotNull ("PublisherIdentityPermission(PermissionState.None)", p);
			PublisherIdentityPermission copy = (PublisherIdentityPermission) p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert ("ToXml-class", se.Attribute ("class").StartsWith (className));
			AssertEquals ("ToXml-version", "1", se.Attribute("version"));
			AssertNull ("ToXml-Unrestricted", se.Attribute("Unrestricted"));
			AssertNull ("Certificate==null", p.Certificate);
		}