/// <summary>Gets all files and directories with the specified <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.</summary> /// <returns>An array containing the paths of the files and directories to which access specified by the <paramref name="access" /> parameter is granted.</returns> /// <param name="access">One of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> values that represents a single type of file access. </param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="access" /> is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- <paramref name="access" /> is <see cref="F:System.Security.Permissions.FileIOPermissionAccess.AllAccess" />, which represents more than one type of file access, or <see cref="F:System.Security.Permissions.FileIOPermissionAccess.NoAccess" />, which does not represent any type of file access. </exception> public string[] GetPathList(FileIOPermissionAccess access) { if ((FileIOPermissionAccess.AllAccess & access) != access) { FileIOPermission.ThrowInvalidFlag(access, true); } ArrayList arrayList = new ArrayList(); switch (access) { case FileIOPermissionAccess.NoAccess: goto IL_9D; case FileIOPermissionAccess.Read: arrayList.AddRange(this.readList); goto IL_9D; case FileIOPermissionAccess.Write: arrayList.AddRange(this.writeList); goto IL_9D; case FileIOPermissionAccess.Append: arrayList.AddRange(this.appendList); goto IL_9D; case FileIOPermissionAccess.PathDiscovery: arrayList.AddRange(this.pathList); goto IL_9D; } FileIOPermission.ThrowInvalidFlag(access, false); IL_9D: return((arrayList.Count <= 0) ? null : ((string[])arrayList.ToArray(typeof(string)))); }
/// <summary>Adds access for the specified file or directory to the existing state of the permission.</summary> /// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> values. </param> /// <param name="path">The absolute path of a file or directory. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- The <paramref name="path" /> parameter is not a valid string.-or- The <paramref name="path" /> parameter did not specify the absolute path to the file or directory. </exception> /// <exception cref="T:System.ArgumentNullException">The <paramref name="path" /> parameter is null. </exception> public void AddPathList(FileIOPermissionAccess access, string path) { if ((FileIOPermissionAccess.AllAccess & access) != access) { FileIOPermission.ThrowInvalidFlag(access, true); } FileIOPermission.ThrowIfInvalidPath(path); this.AddPathInternal(access, path); }
/// <summary>Sets the specified access to the specified files and directories, replacing the current state for the specified access with the new set of paths.</summary> /// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> values. </param> /// <param name="pathList">An array containing the absolute paths of the files and directories. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- An entry in the <paramref name="pathList" /> parameter is not a valid string. </exception> public void SetPathList(FileIOPermissionAccess access, string[] pathList) { if ((FileIOPermissionAccess.AllAccess & access) != access) { FileIOPermission.ThrowInvalidFlag(access, true); } FileIOPermission.ThrowIfInvalidPath(pathList); this.Clear(access); foreach (string path in pathList) { this.AddPathInternal(access, path); } }