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