public override IPermission Intersect(IPermission target)
        {
            FileIOPermission fiop = Cast(target);

            if (fiop == null)
            {
                return(null);
            }

            if (IsUnrestricted())
            {
                return(fiop.Copy());
            }
            if (fiop.IsUnrestricted())
            {
                return(Copy());
            }

            FileIOPermission result = new FileIOPermission(PermissionState.None);

            result.AllFiles      = m_AllFilesAccess & fiop.AllFiles;
            result.AllLocalFiles = m_AllLocalFilesAccess & fiop.AllLocalFiles;

            IntersectKeys(readList, fiop.readList, result.readList);
            IntersectKeys(writeList, fiop.writeList, result.writeList);
            IntersectKeys(appendList, fiop.appendList, result.appendList);
            IntersectKeys(pathList, fiop.pathList, result.pathList);

            return(result.IsEmpty() ? null : result);
        }
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission 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 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)
        {
            FileIOPermission fileIOPermission = FileIOPermission.Cast(target);

            if (fileIOPermission == null)
            {
                return(null);
            }
            if (this.IsUnrestricted())
            {
                return(fileIOPermission.Copy());
            }
            if (fileIOPermission.IsUnrestricted())
            {
                return(this.Copy());
            }
            FileIOPermission fileIOPermission2 = new FileIOPermission(PermissionState.None);

            fileIOPermission2.AllFiles      = (this.m_AllFilesAccess & fileIOPermission.AllFiles);
            fileIOPermission2.AllLocalFiles = (this.m_AllLocalFilesAccess & fileIOPermission.AllLocalFiles);
            FileIOPermission.IntersectKeys(this.readList, fileIOPermission.readList, fileIOPermission2.readList);
            FileIOPermission.IntersectKeys(this.writeList, fileIOPermission.writeList, fileIOPermission2.writeList);
            FileIOPermission.IntersectKeys(this.appendList, fileIOPermission.appendList, fileIOPermission2.appendList);
            FileIOPermission.IntersectKeys(this.pathList, fileIOPermission.pathList, fileIOPermission2.pathList);
            return((!fileIOPermission2.IsEmpty()) ? fileIOPermission2 : null);
        }
        public override IPermission Union(IPermission other)
        {
            FileIOPermission fiop = Cast(other);

            if (fiop == null)
            {
                return(Copy());
            }

            if (IsUnrestricted() || fiop.IsUnrestricted())
            {
                return(new FileIOPermission(PermissionState.Unrestricted));
            }

            if (IsEmpty() && fiop.IsEmpty())
            {
                return(null);
            }

            FileIOPermission result = (FileIOPermission)Copy();

            result.AllFiles      |= fiop.AllFiles;
            result.AllLocalFiles |= fiop.AllLocalFiles;

            string[] paths = fiop.GetPathList(FileIOPermissionAccess.Read);
            if (paths != null)
            {
                UnionKeys(result.readList, paths);
            }

            paths = fiop.GetPathList(FileIOPermissionAccess.Write);
            if (paths != null)
            {
                UnionKeys(result.writeList, paths);
            }

            paths = fiop.GetPathList(FileIOPermissionAccess.Append);
            if (paths != null)
            {
                UnionKeys(result.appendList, paths);
            }

            paths = fiop.GetPathList(FileIOPermissionAccess.PathDiscovery);
            if (paths != null)
            {
                UnionKeys(result.pathList, paths);
            }

            return(result);
        }
        public override bool IsSubsetOf(IPermission target)
        {
            FileIOPermission fiop = Cast(target);

            if (fiop == null)
            {
                return(false);
            }
            if (fiop.IsEmpty())
            {
                return(IsEmpty());
            }

            if (IsUnrestricted())
            {
                return(fiop.IsUnrestricted());
            }
            else if (fiop.IsUnrestricted())
            {
                return(true);
            }

            if ((m_AllFilesAccess & fiop.AllFiles) != m_AllFilesAccess)
            {
                return(false);
            }
            if ((m_AllLocalFilesAccess & fiop.AllLocalFiles) != m_AllLocalFilesAccess)
            {
                return(false);
            }

            if (!KeyIsSubsetOf(appendList, fiop.appendList))
            {
                return(false);
            }
            if (!KeyIsSubsetOf(readList, fiop.readList))
            {
                return(false);
            }
            if (!KeyIsSubsetOf(writeList, fiop.writeList))
            {
                return(false);
            }
            if (!KeyIsSubsetOf(pathList, fiop.pathList))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>Determines whether the current permission is a subset of the specified permission.</summary>
        /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns>
        /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be 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 bool IsSubsetOf(IPermission target)
        {
            FileIOPermission fileIOPermission = FileIOPermission.Cast(target);

            if (fileIOPermission == null)
            {
                return(false);
            }
            if (fileIOPermission.IsEmpty())
            {
                return(this.IsEmpty());
            }
            if (this.IsUnrestricted())
            {
                return(fileIOPermission.IsUnrestricted());
            }
            return(fileIOPermission.IsUnrestricted() || ((this.m_AllFilesAccess & fileIOPermission.AllFiles) == this.m_AllFilesAccess && (this.m_AllLocalFilesAccess & fileIOPermission.AllLocalFiles) == this.m_AllLocalFilesAccess && FileIOPermission.KeyIsSubsetOf(this.appendList, fileIOPermission.appendList) && FileIOPermission.KeyIsSubsetOf(this.readList, fileIOPermission.readList) && FileIOPermission.KeyIsSubsetOf(this.writeList, fileIOPermission.writeList) && FileIOPermission.KeyIsSubsetOf(this.pathList, fileIOPermission.pathList)));
        }
        /// <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="other">A permission to combine with the current permission. It must be the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Union(IPermission other)
        {
            FileIOPermission fileIOPermission = FileIOPermission.Cast(other);

            if (fileIOPermission == null)
            {
                return(this.Copy());
            }
            if (this.IsUnrestricted() || fileIOPermission.IsUnrestricted())
            {
                return(new FileIOPermission(PermissionState.Unrestricted));
            }
            if (this.IsEmpty() && fileIOPermission.IsEmpty())
            {
                return(null);
            }
            FileIOPermission fileIOPermission2 = (FileIOPermission)this.Copy();

            fileIOPermission2.AllFiles      |= fileIOPermission.AllFiles;
            fileIOPermission2.AllLocalFiles |= fileIOPermission.AllLocalFiles;
            string[] array = fileIOPermission.GetPathList(FileIOPermissionAccess.Read);
            if (array != null)
            {
                FileIOPermission.UnionKeys(fileIOPermission2.readList, array);
            }
            array = fileIOPermission.GetPathList(FileIOPermissionAccess.Write);
            if (array != null)
            {
                FileIOPermission.UnionKeys(fileIOPermission2.writeList, array);
            }
            array = fileIOPermission.GetPathList(FileIOPermissionAccess.Append);
            if (array != null)
            {
                FileIOPermission.UnionKeys(fileIOPermission2.appendList, array);
            }
            array = fileIOPermission.GetPathList(FileIOPermissionAccess.PathDiscovery);
            if (array != null)
            {
                FileIOPermission.UnionKeys(fileIOPermission2.pathList, array);
            }
            return(fileIOPermission2);
        }
Exemple #7
0
		public override IPermission Intersect (IPermission target)
		{
			FileIOPermission fiop = Cast (target);
			if (fiop == null)
				return null;

			if (IsUnrestricted ())
				return fiop.Copy ();
			if (fiop.IsUnrestricted ())
				return Copy ();

			FileIOPermission result = new FileIOPermission (PermissionState.None);
			result.AllFiles = m_AllFilesAccess & fiop.AllFiles;
			result.AllLocalFiles = m_AllLocalFilesAccess & fiop.AllLocalFiles;

			IntersectKeys (readList, fiop.readList, result.readList);
			IntersectKeys (writeList, fiop.writeList, result.writeList);
			IntersectKeys (appendList, fiop.appendList, result.appendList);
			IntersectKeys (pathList, fiop.pathList, result.pathList);

			return (result.IsEmpty () ? null : result);
		}