Common
A library of common classes.
PipelineResults.cs
1using System.Collections.Generic;
2
4{
8 public class PipelineResults
9 {
13 public Dictionary<string, object> Inputs { get; } = new Dictionary<string, object>();
14
18 public Dictionary<string, object> Outputs { get; } = new Dictionary<string, object>();
19
23 public bool Success { get; private set; }
24
29 public PipelineResults(Dictionary<string, object> inputs)
30 {
31 Inputs = new Dictionary<string, object>(inputs);
32 }
33
39 public T GetArgument<T>(string key)
40 {
41 if (Outputs.TryGetValue(key, out var value))
42 {
43 if (value is T outputValue)
44 return outputValue;
45 throw new System.InvalidCastException($"Invalid cast for argument: {key}. Attempted to cast {value.GetType()} to {typeof(T)}.");
46 }
47
48 if (Inputs[key] is T inputValue)
49 return inputValue;
50 throw new System.InvalidCastException($"Invalid cast for argument: {key}. Attempted to cast {Inputs[key].GetType()} to {typeof(T)}.");
51 }
52
57 public T GetInput<T>(string key)
58 {
59 if (Inputs[key] is T value)
60 return value;
61 throw new System.InvalidCastException($"Invalid cast for argument: {key}. Attempted to cast {Inputs[key].GetType()} to {typeof(T)}.");
62 }
63
68 public T GetOutput<T>(string key)
69 {
70 if (Outputs[key] is T value)
71 return value;
72 throw new System.InvalidCastException($"Invalid cast for argument: {key}. Attempted to cast {Outputs[key].GetType()} to {typeof(T)}.");
73 }
74
80 public void SetOutput<T>(string key, T value)
81 {
82 Outputs[key] = value;
83 }
84
91 public void AddOutput<T>(string key, T value)
92 {
93 Outputs.Add(key, value);
94 }
95
99 public void Complete()
100 {
101 Success = true;
102 }
103 }
104}
A container for holding pipeline results.
PipelineResults(Dictionary< string, object > inputs)
Initializes a new result.
bool Success
True if the pipeline steps are successful.
void Complete()
Marks the pipeline as successful.
void AddOutput< T >(string key, T value)
Adds the value to the outputs dictionary. Raises an exception if the key already exists.
T GetOutput< T >(string key)
Returns the output for the specified key.
T GetInput< T >(string key)
Returns the input for the specified key.
Dictionary< string, object > Inputs
A dictionary of pipeline inputs.
T GetArgument< T >(string key)
Searches the output and input dictionaries for the key and returns it.
void SetOutput< T >(string key, T value)
Sets the value to the outputs dictionary.
Dictionary< string, object > Outputs
A dictionary of pipeline output results.