| | 1 | | namespace SharpHoundRPC |
| | 2 | | { |
| | 3 | | public class Result<T> |
| | 4 | | { |
| 64 | 5 | | public bool IsSuccess { get; private set; } |
| 2 | 6 | | public NtStatus Status { get; private set; } |
| 64 | 7 | | public T Value { get; private set; } |
| 8 | 8 | | public string Error { get; private set; } |
| 30 | 9 | | public bool IsFailed => !IsSuccess; |
| 2 | 10 | | public bool IsTimeout { get; set; } |
| | 11 | |
|
| | 12 | | public static Result<T> Ok(T value) |
| 31 | 13 | | { |
| 31 | 14 | | return new() {IsSuccess = true, Value = value}; |
| 31 | 15 | | } |
| | 16 | |
|
| | 17 | | public static Result<T> Fail(NtStatus status) |
| 2 | 18 | | { |
| 2 | 19 | | return new() {Status = status}; |
| 2 | 20 | | } |
| | 21 | |
|
| | 22 | | public static Result<T> Fail(string error) |
| 2 | 23 | | { |
| 2 | 24 | | return new() {Error = error}; |
| 2 | 25 | | } |
| | 26 | |
|
| | 27 | | public string SError |
| | 28 | | { |
| | 29 | | get |
| 2 | 30 | | { |
| 2 | 31 | | if (!string.IsNullOrEmpty(Error)) |
| 2 | 32 | | { |
| 2 | 33 | | return Error; |
| | 34 | | } |
| | 35 | |
|
| 0 | 36 | | return Status.ToString(); |
| 2 | 37 | | } |
| | 38 | | } |
| | 39 | |
|
| | 40 | | public static implicit operator Result<T>(T input) |
| 29 | 41 | | { |
| 29 | 42 | | return Ok(input); |
| 29 | 43 | | } |
| | 44 | |
|
| | 45 | | public static implicit operator Result<T>(NtStatus status) |
| 2 | 46 | | { |
| 2 | 47 | | return Fail(status); |
| 2 | 48 | | } |
| | 49 | |
|
| | 50 | | public static implicit operator Result<T>(string error) |
| 0 | 51 | | { |
| 0 | 52 | | return Fail(error); |
| 0 | 53 | | } |
| | 54 | | } |
| | 55 | | } |