| | | 1 | | namespace ArturRios.Output; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a process output that carries a typed data payload. |
| | | 5 | | /// </summary> |
| | | 6 | | /// <typeparam name="T">Type of the data payload.</typeparam> |
| | | 7 | | public class DataOutput<T> : ProcessOutput |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// The payload data for this output. May be <c>null</c>. |
| | | 11 | | /// </summary> |
| | 81 | 12 | | public T? Data { get; protected set; } |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Creates a new <see cref="DataOutput{T}"/> instance. |
| | | 16 | | /// </summary> |
| | 7 | 17 | | public static new DataOutput<T> New => new(); |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Adds or replaces the data payload. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="data">The data to set.</param> |
| | | 23 | | public void AddData(T data) |
| | 1 | 24 | | { |
| | 1 | 25 | | Data = data; |
| | 1 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Fluent helper to set the data payload and return the same instance. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="data">The data to set.</param> |
| | | 32 | | /// <returns>The same <see cref="DataOutput{T}"/> instance for chaining.</returns> |
| | | 33 | | public DataOutput<T> WithData(T data) |
| | 3 | 34 | | { |
| | 3 | 35 | | Data = data; |
| | | 36 | | |
| | 3 | 37 | | return this; |
| | 3 | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Fluent helper to add an error on the current instance. |
| | | 42 | | /// </summary> |
| | | 43 | | /// <param name="error">Error message to add.</param> |
| | | 44 | | public new DataOutput<T> WithError(string error) |
| | 1 | 45 | | { |
| | 1 | 46 | | AddError(error); |
| | | 47 | | |
| | 1 | 48 | | return this; |
| | 1 | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Fluent helper to add multiple errors on the current instance. |
| | | 53 | | /// </summary> |
| | | 54 | | /// <param name="errors">Errors to add.</param> |
| | | 55 | | public new DataOutput<T> WithErrors(IEnumerable<string> errors) |
| | 1 | 56 | | { |
| | 1 | 57 | | AddErrors(errors); |
| | | 58 | | |
| | 1 | 59 | | return this; |
| | 1 | 60 | | } |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Fluent helper to add an informational message on the current instance. |
| | | 64 | | /// </summary> |
| | | 65 | | /// <param name="message">Message to add.</param> |
| | | 66 | | public new DataOutput<T> WithMessage(string message) |
| | 1 | 67 | | { |
| | 1 | 68 | | AddMessage(message); |
| | | 69 | | |
| | 1 | 70 | | return this; |
| | 1 | 71 | | } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Fluent helper to add multiple informational messages on the current instance. |
| | | 75 | | /// </summary> |
| | | 76 | | /// <param name="messages">Messages to add.</param> |
| | | 77 | | public new DataOutput<T> WithMessages(IEnumerable<string> messages) |
| | 1 | 78 | | { |
| | 1 | 79 | | AddMessages(messages); |
| | | 80 | | |
| | 1 | 81 | | return this; |
| | 1 | 82 | | } |
| | | 83 | | } |