参考:https://www.cnblogs.com/hippieZhou/p/11174644.html
摘录代码:
1.定义接口 public interface IPipelineStep<INPUT, OUTPUT> { OUTPUT Process(INPUT input); } 2.实现管道一 public class DoubleToIntStep : IPipelineStep<double, int> { public int Process(double input) { return Convert.ToInt32(input); } } 3.实现管道二 public class IntToStringStep : IPipelineStep<int, string> { public string Process(int input) { return input.ToString(); } } 4.管道互联 public static class PipelineStepExtensions { public static OUTPUT Step<INPUT, OUTPUT>(this INPUT input, IPipelineStep<INPUT, OUTPUT> step) { return step.Process(input); } } 5.调用: class Program { static void Main(string[] args) { double input = 1024.1024; // 构建并使用管道 string result = input.Step(new DoubleToIntStep()) .Step(new IntToStringStep()); Console.WriteLine(result); } }