You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
756 B
32 lines
756 B
1 year ago
|
using System.Diagnostics.CodeAnalysis;
|
||
1 year ago
|
|
||
1 year ago
|
namespace StabilityMatrix.Core.Models;
|
||
1 year ago
|
|
||
1 year ago
|
public readonly record struct TaskResult<T>
|
||
1 year ago
|
{
|
||
1 year ago
|
public readonly T? Result;
|
||
1 year ago
|
public readonly Exception? Exception;
|
||
1 year ago
|
|
||
1 year ago
|
[MemberNotNullWhen(true, nameof(Result))]
|
||
1 year ago
|
public bool IsSuccessful => Exception is null && Result != null;
|
||
1 year ago
|
|
||
|
public TaskResult(T? result, Exception? exception)
|
||
1 year ago
|
{
|
||
1 year ago
|
Result = result;
|
||
1 year ago
|
Exception = exception;
|
||
|
}
|
||
1 year ago
|
|
||
1 year ago
|
public TaskResult(T result)
|
||
1 year ago
|
{
|
||
1 year ago
|
Result = result;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
public static TaskResult<T> FromException(Exception exception) => new(default, exception);
|
||
1 year ago
|
|
||
|
public void Deconstruct(out T? result, out Exception? exception)
|
||
|
{
|
||
|
result = Result;
|
||
|
exception = Exception;
|
||
|
}
|
||
1 year ago
|
}
|