@@ -22,31 +22,34 @@ public static class File
22
22
/// </summary>
23
23
/// <param name="sourceFileName">The file to copy.</param>
24
24
/// <param name="destFileName">The name of the destination file. This cannot be a directory or an existing file.</param>
25
- /// <exception cref="ArgumentException">sourceFileName or destFileName is null or empty</exception>
26
- public static void Copy ( string sourceFileName , string destFileName ) => Copy ( sourceFileName , destFileName , overwrite : false ) ;
25
+ /// <exception cref="ArgumentException"><paramref name="sourceFileName"/> or <paramref name="destFileName"/> is null or empty.</exception>
26
+ public static void Copy ( string sourceFileName , string destFileName )
27
+ {
28
+ Copy ( sourceFileName , destFileName , overwrite : false ) ;
29
+ }
27
30
28
31
/// <summary>
29
32
/// Copies an existing file to a new file. Overwriting a file of the same name is allowed.
30
33
/// </summary>
31
34
/// <param name="sourceFileName">The file to copy.</param>
32
35
/// <param name="destFileName">The name of the destination file. This cannot be a directory.</param>
33
- /// <param name="overwrite"><c>true</c> ; if the destination file can be overwritten; otherwise, <c>false</c>.</param>
34
- /// <exception cref="ArgumentException">sourceFileName or destFileName is null or empty</exception>
36
+ /// <param name="overwrite"><c>true</c> ; if the destination file can be overwritten; otherwise, <c>false</c>.</param>
37
+ /// <exception cref="ArgumentException"><paramref name=" sourceFileName"/> or <paramref name=" destFileName"/> is null or empty. </exception>
35
38
public static void Copy ( string sourceFileName , string destFileName , bool overwrite )
36
39
{
37
40
if ( string . IsNullOrEmpty ( sourceFileName ) )
38
41
{
39
- throw new ArgumentException ( nameof ( sourceFileName ) ) ;
42
+ throw new ArgumentException ( ) ;
40
43
}
41
44
42
45
if ( string . IsNullOrEmpty ( destFileName ) )
43
46
{
44
- throw new ArgumentException ( nameof ( destFileName ) ) ;
47
+ throw new ArgumentException ( ) ;
45
48
}
46
49
47
50
if ( sourceFileName == destFileName )
48
51
{
49
- throw new ArgumentException ( ) ;
52
+ return ;
50
53
}
51
54
52
55
var destMode = overwrite ? FileMode . Create : FileMode . CreateNew ;
@@ -85,7 +88,7 @@ public static void Delete(string path)
85
88
{
86
89
if ( string . IsNullOrEmpty ( path ) )
87
90
{
88
- throw new ArgumentException ( nameof ( path ) ) ;
91
+ throw new ArgumentException ( ) ;
89
92
}
90
93
91
94
Path . CheckInvalidPathChars ( path ) ;
@@ -116,15 +119,15 @@ public static void Delete(string path)
116
119
return ;
117
120
}
118
121
119
- // Check if file is director or read-only (then not allowed to delete)
122
+ // Check if file is directory or read-only (then not allowed to delete)
120
123
if ( ( attributes & ( byte ) FileAttributes . Directory ) != 0 )
121
124
{
122
- throw new IOException ( "Cannot delete directory." , ( int ) IOException . IOExceptionErrorCode . UnauthorizedAccess ) ;
125
+ throw new IOException ( string . Empty , ( int ) IOException . IOExceptionErrorCode . UnauthorizedAccess ) ;
123
126
}
124
127
125
128
if ( ( attributes & ( byte ) FileAttributes . ReadOnly ) != 0 )
126
129
{
127
- throw new IOException ( "File is read-only" , ( int ) IOException . IOExceptionErrorCode . UnauthorizedAccess ) ;
130
+ throw new IOException ( string . Empty , ( int ) IOException . IOExceptionErrorCode . UnauthorizedAccess ) ;
128
131
}
129
132
130
133
DeleteNative ( path ) ;
@@ -149,10 +152,9 @@ public static bool Exists(string path)
149
152
/// Gets the <see cref="FileAttributes"/> of the file on the path.
150
153
/// </summary>
151
154
/// <param name="path">The path to the file.</param>
152
- /// <exception cref="IOException">File not found.</exception>
155
+ /// <exception cref="IOException"><paramref name="path"/> cannot be not found.</exception>
153
156
public static FileAttributes GetAttributes ( string path )
154
157
{
155
- // Adding this check because on my device the GetAttributesNative call throws an Exception instead of IOException if the file is not found
156
158
if ( ! Exists ( path ) )
157
159
{
158
160
throw new IOException ( string . Empty , ( int ) IOException . IOExceptionErrorCode . FileNotFound ) ;
@@ -177,9 +179,9 @@ public static FileAttributes GetAttributes(string path)
177
179
/// <returns>
178
180
/// A <see cref="DateTime" /> structure set to the last write date and time for the specified file or directory.
179
181
/// </returns>
182
+ /// <exception cref="IOException"><paramref name="path"/> cannot be not found.</exception>
180
183
public static DateTime GetLastWriteTime ( string path )
181
184
{
182
- // Adding this check because on my device the GetLastWriteTimeNative call throws an Exception instead of IOException if the file is not found
183
185
if ( ! Exists ( path ) )
184
186
{
185
187
throw new IOException ( string . Empty , ( int ) IOException . IOExceptionErrorCode . FileNotFound ) ;
@@ -193,26 +195,28 @@ public static DateTime GetLastWriteTime(string path)
193
195
/// </summary>
194
196
/// <param name="sourceFileName">The name of the file to move. Must be an absolute path.</param>
195
197
/// <param name="destFileName">The new path and name for the file.</param>
198
+ /// <exception cref="ArgumentException"><paramref name="sourceFileName"/> or <paramref name="destFileName"/> is null or empty.</exception>
199
+ /// <exception cref="IOException"><paramref name="sourceFileName"/> does not exist or <paramref name="destFileName"/> exists.</exception>
196
200
public static void Move ( string sourceFileName , string destFileName )
197
201
{
198
202
if ( string . IsNullOrEmpty ( sourceFileName ) )
199
203
{
200
- throw new ArgumentException ( nameof ( sourceFileName ) ) ;
204
+ throw new ArgumentException ( ) ;
201
205
}
202
206
203
207
if ( string . IsNullOrEmpty ( destFileName ) )
204
208
{
205
- throw new ArgumentException ( nameof ( destFileName ) ) ;
209
+ throw new ArgumentException ( ) ;
206
210
}
207
211
208
212
if ( ! Exists ( sourceFileName ) )
209
213
{
210
- throw new IOException ( nameof ( sourceFileName ) ) ;
214
+ throw new IOException ( string . Empty , ( int ) IOException . IOExceptionErrorCode . FileNotFound ) ;
211
215
}
212
216
213
217
if ( Exists ( destFileName ) )
214
218
{
215
- throw new IOException ( nameof ( destFileName ) ) ;
219
+ throw new IOException ( string . Empty , ( int ) IOException . IOExceptionErrorCode . PathAlreadyExists ) ;
216
220
}
217
221
218
222
if ( sourceFileName == destFileName )
@@ -260,6 +264,7 @@ public static void Move(string sourceFileName, string destFileName)
260
264
/// Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
261
265
/// </summary>
262
266
/// <param name="path">The file to open for reading.</param>
267
+ /// <exception cref="IOException">The end of the file was unexpectedly reached.</exception>
263
268
public static byte [ ] ReadAllBytes ( string path )
264
269
{
265
270
using var stream = OpenRead ( path ) ;
@@ -273,7 +278,7 @@ public static byte[] ReadAllBytes(string path)
273
278
var read = stream . Read ( bytes , index , count > ChunkSize ? ChunkSize : count ) ;
274
279
if ( read <= 0 )
275
280
{
276
- throw new IOException ( "Unexpected end of file" ) ;
281
+ throw new IOException ( ) ;
277
282
}
278
283
279
284
index += read ;
@@ -300,7 +305,6 @@ public static string ReadAllText(string path)
300
305
/// <param name="fileAttributes">A bitwise combination of the enumeration values.</param>
301
306
public static void SetAttributes ( string path , FileAttributes fileAttributes )
302
307
{
303
- // Adding this check because on my device the SetAttributesNative call throws an Exception instead of IOException if the file is not found
304
308
if ( ! Exists ( path ) )
305
309
{
306
310
throw new IOException ( string . Empty , ( int ) IOException . IOExceptionErrorCode . FileNotFound ) ;
0 commit comments