-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCheckResult.cs
More file actions
75 lines (67 loc) · 2.21 KB
/
CheckResult.cs
File metadata and controls
75 lines (67 loc) · 2.21 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
69
70
71
72
73
74
75
using System.Threading.Tasks;
using Ultz.Extensions.Commands.Attributes.Checks;
namespace Ultz.Extensions.Commands.Results.User
{
/// <summary>
/// Represents a <see cref="CheckAttribute" />'s result.
/// </summary>
public class CheckResult : IResult
{
/// <summary>
/// Initialises a new successful <see cref="CheckResult" />.
/// </summary>
public CheckResult()
{
}
/// <summary>
/// Initialises a new failed <see cref="CheckResult" /> with the specified error reason.
/// </summary>
/// <param name="reason"> The error reason. </param>
public CheckResult(string reason)
{
Reason = reason;
}
/// <summary>
/// Gets the error reason.
/// </summary>
public virtual string Reason { get; }
/// <summary>
/// Gets a successful <see cref="CheckResult" />.
/// </summary>
public static CheckResult Successful
=> new CheckResult();
/// <summary>
/// Gets whether the result was successful or not.
/// </summary>
public virtual bool IsSuccessful => Reason == null;
/// <summary>
/// Initialises a new unsuccessful <see cref="CheckResult" />.
/// </summary>
/// <param name="reason"> The error reason. </param>
/// <returns>
/// An unsuccessful <see cref="CheckResult" />.
/// </returns>
public static CheckResult Unsuccessful(string reason)
{
return new CheckResult(reason);
}
/// <summary>
/// Returns <see cref="Reason" />.
/// </summary>
/// <returns>
/// The <see cref="Reason" />.
/// </returns>
public override string ToString()
{
return Reason;
}
/// <summary>
/// Implicitly wraps the provided <see cref="CheckResult" /> in a <see cref="ValueTask{TResult}" />.
/// </summary>
/// <param name="result"> The result to wrap. </param>
public static implicit operator ValueTask<CheckResult>(CheckResult result)
{
return new ValueTask<CheckResult>(result);
}
}
}