Ionite
1 year ago
30 changed files with 108 additions and 30 deletions
@ -1,4 +1,4 @@
|
||||
namespace StabilityMatrix.Models; |
||||
namespace StabilityMatrix.Models.Progress; |
||||
|
||||
public enum ProgressState |
||||
{ |
@ -1,4 +1,4 @@
|
||||
namespace StabilityMatrix.Models; |
||||
namespace StabilityMatrix.Models.Progress; |
||||
|
||||
public enum ProgressType |
||||
{ |
@ -1,11 +1,34 @@
|
||||
using System; |
||||
using System.Diagnostics.CodeAnalysis; |
||||
|
||||
namespace StabilityMatrix.Models; |
||||
|
||||
public class TaskResult<T> |
||||
public readonly record struct TaskResult<T> |
||||
{ |
||||
public T? Result { get; set; } |
||||
public Exception? Exception { get; set; } |
||||
public readonly T? Result; |
||||
public readonly Exception? Exception = null; |
||||
|
||||
[MemberNotNullWhen(true, nameof(Result))] |
||||
public bool IsSuccessful => Exception is null && Result != null; |
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global |
||||
private TaskResult(Exception exception) |
||||
{ |
||||
Result = default; |
||||
Exception = exception; |
||||
} |
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global |
||||
public TaskResult(T? Result) |
||||
{ |
||||
this.Result = Result; |
||||
} |
||||
|
||||
public TaskResult<T> FromException(Exception exception) => new(exception: exception); |
||||
|
||||
public void Deconstruct(out T? result, out Exception? exception) |
||||
{ |
||||
result = Result; |
||||
exception = Exception; |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue