Пример #1
0
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission object that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
        /// <param name="target">A permission to intersect 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. </exception>
        public override IPermission Intersect(IPermission target)
        {
            SecurityPermission securityPermission = this.Cast(target);

            if (securityPermission == null)
            {
                return(null);
            }
            if (this.IsEmpty() || securityPermission.IsEmpty())
            {
                return(null);
            }
            if (this.IsUnrestricted() && securityPermission.IsUnrestricted())
            {
                return(new SecurityPermission(PermissionState.Unrestricted));
            }
            if (this.IsUnrestricted())
            {
                return(securityPermission.Copy());
            }
            if (securityPermission.IsUnrestricted())
            {
                return(this.Copy());
            }
            SecurityPermissionFlag securityPermissionFlag = this.flags & securityPermission.flags;

            if (securityPermissionFlag == SecurityPermissionFlag.NoFlags)
            {
                return(null);
            }
            return(new SecurityPermission(securityPermissionFlag));
        }
Пример #2
0
        public override IPermission Intersect(IPermission target)
        {
            SecurityPermission sp = Cast(target);

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

            if (this.IsUnrestricted() && sp.IsUnrestricted())
            {
                return(new SecurityPermission(PermissionState.Unrestricted));
            }
            if (this.IsUnrestricted())
            {
                return(sp.Copy());
            }
            if (sp.IsUnrestricted())
            {
                return(this.Copy());
            }

            SecurityPermissionFlag f = flags & sp.flags;

            if (f == SecurityPermissionFlag.NoFlags)
            {
                return(null);
            }
            else
            {
                return(new SecurityPermission(f));
            }
        }