forked from TestableIO/System.IO.Abstractions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystemOperationEventArgs.cs
More file actions
68 lines (59 loc) · 2.23 KB
/
FileSystemOperationEventArgs.cs
File metadata and controls
68 lines (59 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
namespace System.IO.Abstractions.TestingHelpers.Events;
/// <summary>
/// Provides data for file system operation events.
/// </summary>
public class FileSystemOperationEventArgs : EventArgs
{
private OperationResponse response;
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemOperationEventArgs"/> class.
/// </summary>
/// <param name="path">The path of the resource being operated on.</param>
/// <param name="operation">The type of operation.</param>
/// <param name="resourceType">The type of resource.</param>
/// <param name="phase">The phase of the operation.</param>
public FileSystemOperationEventArgs(
string path,
FileOperation operation,
ResourceType resourceType,
OperationPhase phase)
{
Path = path ?? throw new ArgumentNullException(nameof(path));
Operation = operation;
ResourceType = resourceType;
Phase = phase;
}
/// <summary>
/// Gets the path of the resource being operated on.
/// </summary>
public string Path { get; }
/// <summary>
/// Gets the type of operation being performed.
/// </summary>
public FileOperation Operation { get; }
/// <summary>
/// Gets the type of resource being operated on.
/// </summary>
public ResourceType ResourceType { get; }
/// <summary>
/// Gets the phase of the operation.
/// </summary>
public OperationPhase Phase { get; }
/// <summary>
/// Sets a response for the operation. Only valid for Before phase events.
/// </summary>
/// <param name="response">The response to set.</param>
/// <exception cref="InvalidOperationException">Thrown when called on an After phase event.</exception>
public void SetResponse(OperationResponse response)
{
if (Phase != OperationPhase.Before)
{
throw new InvalidOperationException("Response can only be set for Before phase events.");
}
this.response = response ?? throw new ArgumentNullException(nameof(response));
}
/// <summary>
/// Gets the response set for this operation, if any.
/// </summary>
internal OperationResponse GetResponse() => response;
}