| | 1 | | namespace SharpHoundCommonLib { |
| | 2 | | public class Result<T> : Result { |
| 70 | 3 | | public T Value { get; set; } |
| | 4 | |
|
| 98 | 5 | | protected Result(T value, bool success, string error) : base(success, error) { |
| 49 | 6 | | Value = value; |
| 49 | 7 | | } |
| | 8 | |
|
| 0 | 9 | | public new static Result<T> Fail(string message) { |
| 0 | 10 | | return new Result<T>(default, false, message); |
| 0 | 11 | | } |
| | 12 | |
|
| 0 | 13 | | public static Result<T> Fail() { |
| 0 | 14 | | return new Result<T>(default, false, string.Empty); |
| 0 | 15 | | } |
| | 16 | |
|
| 20 | 17 | | public static Result<T> Ok(T value) { |
| 20 | 18 | | return new Result<T>(value, true, string.Empty); |
| 20 | 19 | | } |
| | 20 | | } |
| | 21 | |
|
| | 22 | | public class Result { |
| | 23 | |
|
| | 24 | | public string Error { get; set; } |
| | 25 | | public bool IsSuccess => string.IsNullOrWhiteSpace(Error) && Success; |
| | 26 | | private bool Success { get; set; } |
| | 27 | |
|
| | 28 | | protected Result(bool success, string error) { |
| | 29 | | Success = success; |
| | 30 | | Error = error; |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public static Result Fail(string message) { |
| | 34 | | return new Result(false, message); |
| | 35 | | } |
| | 36 | |
|
| | 37 | | public static Result Ok() { |
| | 38 | | return new Result(true, string.Empty); |
| | 39 | | } |
| | 40 | | } |
| | 41 | | } |