override public IPermission Union(IPermission target)
        {
            if (null == target)
            {
                return(this.Copy());
            }
            if (target.GetType() != this.GetType())
            {
                throw ADP.PermissionTypeMismatch();
            }
            if (IsUnrestricted())
            { // MDAC 84803
                return(this.Copy());
            }

            SqlClientPermission newPermission = (SqlClientPermission)target.Copy();

            if (!newPermission.IsUnrestricted())
            {
                newPermission.AllowBlankPassword |= AllowBlankPassword;

                if (null != _keyvalues)
                {
                    foreach (DBConnectionString entry in _keyvalues)
                    {
                        newPermission.AddPermissionEntry(entry);
                    }
                }
            }
            return(newPermission.IsEmpty() ? null : newPermission);
        }
        // Modified CopyFrom to make sure that we copy the Name Value Pair
        private void CopyFrom(SqlClientPermission permission)
        {
            if (!_IsUnrestricted)
            {
                if (null != permission._keyvalues)
                {
                    _keyvalues = (ArrayList)permission._keyvalues.Clone();

                    if (null != permission._keyvaluetree)
                    {
                        _keyvaluetree = permission._keyvaluetree.CopyNameValue();
                    }
                }
            }
        }
        override public IPermission Intersect(IPermission target)
        { // used during Deny actions
            if (null == target)
            {
                return(null);
            }
            if (target.GetType() != this.GetType())
            {
                throw ADP.PermissionTypeMismatch();
            }
            if (this.IsUnrestricted())
            { // MDAC 84803, NDPWhidbey 29121
                return(target.Copy());
            }

            DBDataPermission operand = (DBDataPermission)target;

            if (operand.IsUnrestricted())
            { // NDPWhidbey 29121
                return(this.Copy());
            }

            SqlClientPermission newPermission = (SqlClientPermission)operand.Copy();

            newPermission.AllowBlankPassword &= AllowBlankPassword;

            if ((null != _keyvalues) && (null != newPermission._keyvalues))
            {
                newPermission._keyvalues.Clear();

                newPermission._keyvaluetree.Intersect(newPermission._keyvalues, _keyvaluetree);
            }
            else
            {
                // either target.Add or this.Add have not been called
                // return a non-null object so IsSubset calls will fail
                newPermission._keyvalues    = null;
                newPermission._keyvaluetree = null;
            }

            if (newPermission.IsEmpty())
            { // no intersection, MDAC 86773
                newPermission = null;
            }
            return(newPermission);
        }
        override public bool IsSubsetOf(IPermission target)
        {
            if (null == target)
            {
                return(IsEmpty());
            }
            if (target.GetType() != this.GetType())
            {
                throw ADP.PermissionTypeMismatch();
            }

            SqlClientPermission superset = (target as SqlClientPermission);

            bool subset = superset.IsUnrestricted();

            if (!subset)
            {
                if (!IsUnrestricted() &&
                    (!AllowBlankPassword || superset.AllowBlankPassword) &&
                    ((null == _keyvalues) || (null != superset._keyvaluetree)))
                {
                    subset = true;
                    if (null != _keyvalues)
                    {
                        foreach (DBConnectionString kventry in _keyvalues)
                        {
                            if (!superset._keyvaluetree.CheckValueForKeyPermit(kventry))
                            {
                                subset = false;
                                break;
                            }
                        }
                    }
                }
            }
            return(subset);
        }
 private SqlClientPermission(SqlClientPermission permission) : base(permission)   // for Copy
     // Explicitly copyFrom to clone the key value pairs
 {
     CopyFrom(permission);
 }