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