| | | 1 | | namespace NexusLabs.Needlr.AgentFramework.Workspace; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Result of a workspace operation — either a success value of type |
| | | 5 | | /// <typeparamref name="T"/> or a failure carrying an <see cref="System.Exception"/>. |
| | | 6 | | /// </summary> |
| | | 7 | | /// <typeparam name="T">The operation-specific success data type.</typeparam> |
| | | 8 | | public sealed class WorkspaceResult<T> |
| | | 9 | | { |
| | | 10 | | /// <summary>Whether the operation succeeded.</summary> |
| | 16 | 11 | | public bool Success { get; } |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// The success value. Only meaningful when <see cref="Success"/> is |
| | | 15 | | /// <see langword="true"/>. |
| | | 16 | | /// </summary> |
| | 30 | 17 | | public T Value { get; } |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// The exception that caused the failure. Only meaningful when |
| | | 21 | | /// <see cref="Success"/> is <see langword="false"/>. |
| | | 22 | | /// </summary> |
| | 8 | 23 | | public Exception? Exception { get; } |
| | | 24 | | |
| | 148 | 25 | | private WorkspaceResult(T value) |
| | | 26 | | { |
| | 148 | 27 | | Success = true; |
| | 148 | 28 | | Value = value; |
| | 148 | 29 | | } |
| | | 30 | | |
| | 6 | 31 | | private WorkspaceResult(Exception exception) |
| | | 32 | | { |
| | 6 | 33 | | Success = false; |
| | 6 | 34 | | Exception = exception; |
| | 6 | 35 | | Value = default!; |
| | 6 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary>Creates a success result carrying <paramref name="value"/>.</summary> |
| | 148 | 39 | | public static WorkspaceResult<T> Ok(T value) => new(value); |
| | | 40 | | |
| | | 41 | | /// <summary>Creates a failure result carrying <paramref name="exception"/>.</summary> |
| | 6 | 42 | | public static WorkspaceResult<T> Fail(Exception exception) => new(exception); |
| | | 43 | | } |