Copy() public method

public Copy ( ) : IPermission
return IPermission
Beispiel #1
0
        /// <include file='doc\StrongNameIdentityPermission.uex' path='docs/doc[@for="StrongNameIdentityPermission.Union"]/*' />
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.m_publicKeyBlob != null?this.Copy() : null);
            }
            else if (!VerifyType(target))
            {
                throw new
                      ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
                          );
            }

            StrongNameIdentityPermission operand = (StrongNameIdentityPermission)target;

            // Union is only defined on permissions where one is a subset of the other.
            // For Union, simply return a copy of whichever contains the other.

            if (operand.IsSubsetOf(this))
            {
                return(this.Copy());
            }
            else if (this.IsSubsetOf(operand))
            {
                return(operand.Copy());
            }
            else
            {
                return(null);
            }
        }
        public override IPermission Union(IPermission target)
        {
            StrongNameIdentityPermission snip = Cast(target);

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

            if (IsEmpty())
            {
                return(snip.Copy());
            }

            StrongNameIdentityPermission union = (StrongNameIdentityPermission)Copy();

            foreach (SNIP e in snip._list)
            {
                if (!IsEmpty(e) && !Contains(e))
                {
                    union._list.Add(e);
                }
            }
            return(union);
        }
		public void PermissionStateNone ()
		{
			StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
			Assert.AreEqual (String.Empty, snip.Name, "Name");
			Assert.IsNull (snip.PublicKey, "PublicKey");
			Assert.AreEqual ("0.0", snip.Version.ToString (), "Version");

			SecurityElement se = snip.ToXml ();
#if NET_2_0
			Assert.IsNull (se.Attribute ("Name"), "Xml-Name");
			Assert.IsNull (se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
#else
			Assert.AreEqual (String.Empty, se.Attribute ("Name"), "Xml-Name");
			Assert.AreEqual ("0.0", se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
#endif
			Assert.IsNull (se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob");

			// because Name == String.Empty, which is illegal using the other constructor
			StrongNameIdentityPermission copy = (StrongNameIdentityPermission) snip.Copy ();
			Assert.AreEqual (String.Empty, copy.Name, "Copy-Name");
#if NET_2_0
			// Strangely once copied the Name becomes equals to String.Empty in 2.0 [FDBK19351]
			Assert.IsNull (se.Attribute ("AssemblyVersion"), "Copy-Version");
#else
			Assert.AreEqual ("0.0", copy.Version.ToString (), "Copy-Version");
#endif
			Assert.IsNull (copy.PublicKey, "Copy-PublicKey");
		}
        /// <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, or <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: 0x06002642 RID: 9794 RVA: 0x0008A500 File Offset: 0x00088700
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            StrongNameIdentityPermission strongNameIdentityPermission = target as StrongNameIdentityPermission;

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

            foreach (StrongName2 strongName in this.m_strongNames)
            {
                foreach (StrongName2 target2 in strongNameIdentityPermission.m_strongNames)
                {
                    StrongName2 strongName2 = strongName.Intersect(target2);
                    if (strongName2 != null)
                    {
                        list.Add(strongName2);
                    }
                }
            }
            if (list.Count == 0)
            {
                return(null);
            }
            return(new StrongNameIdentityPermission(PermissionState.None)
            {
                m_strongNames = list.ToArray()
            });
        }
        /// <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);
            }
            StrongNameIdentityPermission identityPermission = target as StrongNameIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            if (this.m_unrestricted && identityPermission.m_unrestricted)
            {
                return (IPermission) new StrongNameIdentityPermission(PermissionState.None)
                       {
                           m_unrestricted = true
                       }
            }
            ;
            if (this.m_unrestricted)
            {
                return(identityPermission.Copy());
            }
            if (identityPermission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_strongNames == null || identityPermission.m_strongNames == null || (this.m_strongNames.Length == 0 || identityPermission.m_strongNames.Length == 0))
            {
                return((IPermission)null);
            }
            List <StrongName2> strongName2List = new List <StrongName2>();

            foreach (StrongName2 mStrongName1 in this.m_strongNames)
            {
                foreach (StrongName2 mStrongName2 in identityPermission.m_strongNames)
                {
                    StrongName2 strongName2 = mStrongName1.Intersect(mStrongName2);
                    if (strongName2 != null)
                    {
                        strongName2List.Add(strongName2);
                    }
                }
            }
            if (strongName2List.Count == 0)
            {
                return((IPermission)null);
            }
            return((IPermission) new StrongNameIdentityPermission(PermissionState.None)
            {
                m_strongNames = strongName2List.ToArray()
            });
        }
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            StrongNameIdentityPermission that = target as StrongNameIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            if (this.m_unrestricted && that.m_unrestricted)
            {
                StrongNameIdentityPermission res = new StrongNameIdentityPermission(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_strongNames == null || that.m_strongNames == null || this.m_strongNames.Length == 0 || that.m_strongNames.Length == 0)
            {
                return(null);
            }
            List <StrongName2> alStrongNames = new List <StrongName2>();

            foreach (StrongName2 snThis in this.m_strongNames)
            {
                foreach (StrongName2 snThat in that.m_strongNames)
                {
                    StrongName2 snInt = (StrongName2)snThis.Intersect(snThat);
                    if (snInt != null)
                    {
                        alStrongNames.Add(snInt);
                    }
                }
            }
            if (alStrongNames.Count == 0)
            {
                return(null);
            }
            StrongNameIdentityPermission result = new StrongNameIdentityPermission(PermissionState.None);

            result.m_strongNames = alStrongNames.ToArray();
            return(result);
        }
        public override IPermission Union(IPermission target)
        {
            StrongNameIdentityPermission snip = Cast(target);

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

            if (IsEmpty())
            {
                return(snip.Copy());
            }

            if (!PublicKey.Equals(snip.PublicKey))
            {
                return(null);
            }

            string n = Name;

            if ((n == null) || (n.Length == 0))
            {
                n = snip.Name;
            }
            else if (Match(snip.Name))
            {
                n = ((Name.Length > snip.Name.Length) ? Name : snip.Name);
            }
            else if ((snip.Name != null) && (snip.Name.Length > 0) && (n != snip.Name))
            {
                return(null);
            }

            Version v = Version;

            if (v == null)
            {
                v = snip.Version;
            }
            else if ((snip.Version != null) && (v != snip.Version))
            {
                return(null);
            }

            return(new StrongNameIdentityPermission(PublicKey, n, v));
        }
		public void PermissionStateUnrestricted ()
		{
			// In 2.0 Unrestricted are permitted for identity permissions
			StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.Unrestricted);
			Assert.AreEqual (String.Empty, snip.Name, "Name");
			Assert.IsNull (snip.PublicKey, "PublicKey");
			Assert.AreEqual ("0.0", snip.Version.ToString (), "Version");
			SecurityElement se = snip.ToXml ();
			Assert.IsNull (se.Attribute ("Name"), "Xml-Name");
			Assert.IsNull (se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob");
			Assert.IsNull (se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
			StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy ();
			Assert.IsTrue (snip.Equals (copy), "snip Equals copy");
			Assert.IsTrue (copy.Equals (snip), "copy Equals snip");
			// and they aren't equals to None
			Assert.IsFalse (snip.Equals (new StrongNameIdentityPermission (PermissionState.None)), "Not Equals None");
		}
        /// <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 one is a subset of the other.</exception>
        public override IPermission Union(IPermission target)
        {
            StrongNameIdentityPermission strongNameIdentityPermission = this.Cast(target);

            if (strongNameIdentityPermission == null || strongNameIdentityPermission.IsEmpty())
            {
                return(this.Copy());
            }
            if (this.IsEmpty())
            {
                return(strongNameIdentityPermission.Copy());
            }
            StrongNameIdentityPermission strongNameIdentityPermission2 = (StrongNameIdentityPermission)this.Copy();

            foreach (object obj in strongNameIdentityPermission._list)
            {
                StrongNameIdentityPermission.SNIP snip = (StrongNameIdentityPermission.SNIP)obj;
                if (!this.IsEmpty(snip) && !this.Contains(snip))
                {
                    strongNameIdentityPermission2._list.Add(snip);
                }
            }
            return(strongNameIdentityPermission2);
        }
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if ((this.m_strongNames == null || this.m_strongNames.Length == 0) && !this.m_unrestricted)
                {
                    return(null);
                }
                return(this.Copy());
            }
            StrongNameIdentityPermission that = target as StrongNameIdentityPermission;

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

            foreach (StrongName2 snThis in this.m_strongNames)
            {
                alStrongNames.Add(snThis);
            }
            foreach (StrongName2 snThat in that.m_strongNames)
            {
                bool bDupe = false;
                foreach (StrongName2 sn in alStrongNames)
                {
                    if (snThat.Equals(sn))
                    {
                        bDupe = true;
                        break;
                    }
                }
                if (!bDupe)
                {
                    alStrongNames.Add(snThat);
                }
            }
            StrongNameIdentityPermission result = new StrongNameIdentityPermission(PermissionState.None);

            result.m_strongNames = alStrongNames.ToArray();
            return(result);
        }
		public void Copy_NameEmpty ()
		{
			StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
			snip.PublicKey = new StrongNamePublicKeyBlob (ecma);
			snip.Version = new Version ("1.2.3.4");

			// because Name == String.Empty, which is illegal using the other constructor
			// but (somewhat) required to copy the teo other informations
			StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy ();
#if NET_2_0
			Assert.IsTrue (copy.Equals (snip), "Equals");
#else
			Assert.AreEqual (copy.ToXml ().ToString (), snip.ToXml ().ToString (), "Equals-XML");
#endif
		}
		public void StrongNameIdentityPermission_All ()
		{
			StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
			StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
			Assert.AreEqual ("mono", snip.Name, "Name");
			Assert.AreEqual ("00000000000000000400000000000000", snip.PublicKey.ToString (), "PublicKey");
			Assert.AreEqual ("1.2.3.4", snip.Version.ToString (), "Version");

			SecurityElement se = snip.ToXml ();
			Assert.AreEqual ("mono", se.Attribute ("Name"), "Xml-Name");
			Assert.AreEqual ("00000000000000000400000000000000", se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob");
			Assert.AreEqual ("1.2.3.4", se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");

			StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy ();
			Assert.AreEqual ("mono", se.Attribute ("Name"), "Copy-Name");
			Assert.AreEqual ("00000000000000000400000000000000", se.Attribute ("PublicKeyBlob"), "Copy-PublicKeyBlob");
			Assert.AreEqual ("1.2.3.4", se.Attribute ("AssemblyVersion"), "Copy-AssemblyVersion");
		}
 /// <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 and one is a subset of the other.</exception>
 // Token: 0x06002643 RID: 9795 RVA: 0x0008A624 File Offset: 0x00088824
 public override IPermission Union(IPermission target)
 {
     if (target == null)
     {
         if ((this.m_strongNames == null || this.m_strongNames.Length == 0) && !this.m_unrestricted)
         {
             return(null);
         }
         return(this.Copy());
     }
     else
     {
         StrongNameIdentityPermission strongNameIdentityPermission = target as StrongNameIdentityPermission;
         if (strongNameIdentityPermission == null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
             {
                 base.GetType().FullName
             }));
         }
         if (this.m_unrestricted || strongNameIdentityPermission.m_unrestricted)
         {
             return(new StrongNameIdentityPermission(PermissionState.None)
             {
                 m_unrestricted = true
             });
         }
         if (this.m_strongNames == null || this.m_strongNames.Length == 0)
         {
             if (strongNameIdentityPermission.m_strongNames == null || strongNameIdentityPermission.m_strongNames.Length == 0)
             {
                 return(null);
             }
             return(strongNameIdentityPermission.Copy());
         }
         else
         {
             if (strongNameIdentityPermission.m_strongNames == null || strongNameIdentityPermission.m_strongNames.Length == 0)
             {
                 return(this.Copy());
             }
             List <StrongName2> list = new List <StrongName2>();
             foreach (StrongName2 item in this.m_strongNames)
             {
                 list.Add(item);
             }
             foreach (StrongName2 strongName in strongNameIdentityPermission.m_strongNames)
             {
                 bool flag = false;
                 foreach (StrongName2 target2 in list)
                 {
                     if (strongName.Equals(target2))
                     {
                         flag = true;
                         break;
                     }
                 }
                 if (!flag)
                 {
                     list.Add(strongName);
                 }
             }
             return(new StrongNameIdentityPermission(PermissionState.None)
             {
                 m_strongNames = list.ToArray()
             });
         }
     }
 }
        /// <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_strongNames == null || this.m_strongNames.Length == 0) && !this.m_unrestricted)
                {
                    return((IPermission)null);
                }
                return(this.Copy());
            }
            StrongNameIdentityPermission identityPermission = target as StrongNameIdentityPermission;

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

            foreach (StrongName2 mStrongName in this.m_strongNames)
            {
                strongName2List.Add(mStrongName);
            }
            foreach (StrongName2 mStrongName in identityPermission.m_strongNames)
            {
                bool flag = false;
                foreach (StrongName2 target1 in strongName2List)
                {
                    if (mStrongName.Equals(target1))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    strongName2List.Add(mStrongName);
                }
            }
            return((IPermission) new StrongNameIdentityPermission(PermissionState.None)
            {
                m_strongNames = strongName2List.ToArray()
            });
        }