/// <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); }
/// <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); }