TPL Dataflow 提供了一个用于转换输入的TransformBlock
,例如:
var tb = new TransformBlock<int, int>(i => i * 2);
是否可能不输出输入的某些部分,例如如果输入未通过某些验证测试?
var tb = new TransformBlock<InputType, OutputType>(i =>
{
if (!ValidateInput(i))
{
// Do something to not output anything for this input
}
// Normal output
}
如果不可能实现,那么达到这个目标的最佳模式是什么?
类似以下内容?
BufferBlock<OutputType> output = new BufferBlock<OutputType>();
var ab = new ActionBlock<InputType>(i =>
{
if (ValidateInput(i))
{
output.Post(MyTransform(i));
}
}