|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | + |
| 4 | +namespace FluentPipelines |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// A builder that builds a pipeline with input data and no output data. |
| 8 | + /// </summary> |
| 9 | + /// <typeparam name="TInput">The type of data used as input to the pipeline.</typeparam> |
| 10 | + public class InPipelineBuilder<TInput> : IInPipelineBuilder<TInput> |
| 11 | + { |
| 12 | + /// <summary> |
| 13 | + /// Gets the collection of steps added to the builder, which will be used to construct the pipeline. |
| 14 | + /// <para><b>IMPORTANT:</b> The first step must take <typeparamref name="TInput"/> as input, otherwise the built-in pipeline types will not work.</para> |
| 15 | + /// </summary> |
| 16 | + protected internal List<PipelineStep> Steps { get; } |
| 17 | + |
| 18 | + /// <summary> |
| 19 | + /// Initializes a new instance of the <see cref="InPipelineBuilder{TInput}"/> class. |
| 20 | + /// </summary> |
| 21 | + /// <param name="steps"> |
| 22 | + /// The collection of steps to add to the builder, which will be used to construct the pipeline. |
| 23 | + /// <para><b>IMPORTANT:</b> The first step must take <typeparamref name="TInput"/> as input, otherwise the built-in pipeline types will not work.</para> |
| 24 | + /// <para><b>IMPORTANT:</b> <paramref name="steps"/> is taken by reference! The list is NOT copied!</para> |
| 25 | + /// </param> |
| 26 | + protected internal InPipelineBuilder(List<PipelineStep> steps) |
| 27 | + { |
| 28 | + Steps = steps ?? throw new ArgumentNullException(nameof(steps)); |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Initializes a new instance of the <see cref="InPipelineBuilder{TInput}"/> class. |
| 33 | + /// </summary> |
| 34 | + /// <param name="firstStep"> |
| 35 | + /// The first step of the pipeline, processing the input data. |
| 36 | + /// <para><b>IMPORTANT:</b> This must take <typeparamref name="TInput"/> as input, otherwise the built-in pipeline types will not work.</para> |
| 37 | + /// </param> |
| 38 | + public InPipelineBuilder(PipelineStep firstStep) |
| 39 | + { |
| 40 | + if(firstStep is null) |
| 41 | + throw new ArgumentNullException(nameof(firstStep)); |
| 42 | + |
| 43 | + Steps = new List<PipelineStep>() { firstStep }; |
| 44 | + } |
| 45 | + |
| 46 | + /// <inheritdoc/> |
| 47 | + public virtual IInPipeline<TInput> Build() |
| 48 | + { |
| 49 | + return new InPipeline<TInput>(Steps); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments