Exemple #1
0
        /// <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 null if the intersectionis empty.</returns>
        public override System.Security.IPermission Intersect(System.Security.IPermission target)
        {
            // If 'target' is null, return null.
            if (target == null)
            {
                return(null);
            }

            // Both objects must be the same type.
            FileAccessPermission filePerm = VerifyTypeMatch(target);

            // If 'this' and 'target' are unrestricted, return a new unrestricted permission.
            if (_specifiedAsUnrestricted && filePerm._specifiedAsUnrestricted)
            {
                return(Clone(true, PermissionType.Unrestricted));
            }

            // Calculate the intersected permissions. If there are none, return null.
            PermissionType val = (PermissionType)Math.Min((Int32)_permission, (Int32)filePerm._permission);

            if (val == 0)
            {
                return(null);
            }

            // Get the intersect.
            val = new PermissionSource(_permission).Intersect(filePerm._permission);

            // Return a new object with the intersected permission value.
            return(Clone(false, val));
        }
Exemple #2
0
        /// <summary>
        /// Clone the file access permission.
        /// </summary>
        /// <param name="specifiedAsUnrestricted">True if unrestricted; else restricted.</param>
        /// <param name="flags">The permission flags.</param>
        /// <returns>The file access permission clone.</returns>
        private FileAccessPermission Clone(Boolean specifiedAsUnrestricted, PermissionType flags)
        {
            FileAccessPermission filePerm = (FileAccessPermission)Clone();

            filePerm._specifiedAsUnrestricted = specifiedAsUnrestricted;
            filePerm._permission = specifiedAsUnrestricted ? PermissionType.Unrestricted : _permission;
            return(filePerm);
        }
Exemple #3
0
        /// <summary>
        /// Determines whether the current permission
        /// is a subset of the specified permission.
        /// </summary>
        /// <param name="target">A permission that is to be tested for the subset relationship.
        /// This permission must be of the same type as the current permission.</param>
        /// <returns>True if the current permission is a subset of the specified permission; otherwise, false.</returns>
        public override bool IsSubsetOf(System.Security.IPermission target)
        {
            // If 'target' is null and this permission allows nothing, return true.
            if (target == null)
            {
                return(_permission == 0);
            }

            // Both objects must be the same type.
            FileAccessPermission filePerm = VerifyTypeMatch(target);

            // Return true if the permissions of 'this' is a subset of 'target'.
            return(new PermissionSource(_permission).IsSubsetOf(filePerm._permission));
        }
Exemple #4
0
        /// <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>
        public override System.Security.IPermission Union(System.Security.IPermission target)
        {
            // If 'target' is null, then return a copy of 'this'.
            if (target == null)
            {
                return(Copy());
            }

            // Both objects must be the same type.
            FileAccessPermission filePerm = VerifyTypeMatch(target);

            // If 'this' or 'target' are unrestricted, return a new unrestricted permission.
            if (_specifiedAsUnrestricted || filePerm._specifiedAsUnrestricted)
            {
                return(Clone(true, PermissionType.Unrestricted));
            }

            // Return a new object with the calculated, unioned permission value.
            return(Clone(false, new PermissionSource(_permission).Union(filePerm._permission)));
        }