IsSubsetOf() public method

public IsSubsetOf ( IPermission target ) : bool
target IPermission
return bool
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 void Union ()
		{
			StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
			StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));

			StrongNameIdentityPermission union = (StrongNameIdentityPermission)snip.Union (null);
			Compare (snip, union, "snip U null");

			StrongNameIdentityPermission empty = new StrongNameIdentityPermission (PermissionState.None);
			union = (StrongNameIdentityPermission)snip.Union (empty);
			Compare (snip, union, "snip U empty");

			union = (StrongNameIdentityPermission)snip.Union (snip);
			Compare (snip, union, "snip U snip");

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

			StrongNameIdentityPermission samePk = new StrongNameIdentityPermission (blob, null, null);
			union = (StrongNameIdentityPermission)snip.Union (samePk);
#if !NET_2_0
			// can't compare the properties with multiple entries
			Compare (snip, union, "snip U samePk");
#endif
			Assert.IsTrue (snip.IsSubsetOf (union), "snip.IsSubsetOf (union)");

			union = (StrongNameIdentityPermission)samePk.Union (snip);
#if !NET_2_0
			// can't compare the properties with multiple entries
			Compare (snip, union, "samePk U snip");
#endif
			Assert.IsTrue (samePk.IsSubsetOf (union), "snip.IsSubsetOf (union)");
		}
		public void IsSubsetOf_DifferentPermissions ()
		{
			StrongNameIdentityPermission a = new StrongNameIdentityPermission (PermissionState.None);
			SecurityPermission b = new SecurityPermission (PermissionState.None);
			a.IsSubsetOf (b);
		}
		public void IsSubsetOf_Corlib ()
		{
			Version fx11 = new Version (1, 0, 5000, 0);
			StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
			StrongNameIdentityPermission granted = new StrongNameIdentityPermission (blob, "mscorlib", fx11);

			StrongNameIdentityPermission demanded = new StrongNameIdentityPermission (blob, null, null);
			Assert.IsTrue (demanded.IsSubsetOf (granted), "pk");

			demanded = new StrongNameIdentityPermission (blob, "mscorlib", null);
			Assert.IsTrue (demanded.IsSubsetOf (granted), "pk+name");

			demanded = new StrongNameIdentityPermission (blob, null, fx11);
			Assert.IsTrue (demanded.IsSubsetOf (granted), "pk+v");

			demanded = new StrongNameIdentityPermission (blob, "mscorlib", fx11);
			Assert.IsTrue (demanded.IsSubsetOf (granted), "pk+name+v");
		}
		public void IsSubsetOf ()
		{
			StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
			StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
			Assert.IsFalse (snip.IsSubsetOf (null), "snip.IsSubsetOf (null)");

			StrongNameIdentityPermission empty = new StrongNameIdentityPermission (PermissionState.None);
			Assert.IsTrue (empty.IsSubsetOf (null), "empty.IsSubsetOf (null)");
		}