是否存在用于返回 Enumerable 中所有项目的标准模式?
我经常发现我的一些代码反映了以下模式:
public IEnumerable<object> YieldReturningFunction()
{
...
[logic and various standard yield return]
...
foreach(object obj in methodReturningEnumerable(x,y,z))
{
yield return obj;
}
}
明确使用 foreach 循环只是为了向我返回可枚举的代码气味的结果。
显然,我可以通过显式构建一个 Enumerable 并将每个标准 yield return 的结果添加到它以及添加methodReturningEnumerable的结果范围来放弃使用 yield return 来增加我的代码的复杂性。这将是不幸的,因此我希望存在一种更好的方法来管理收益率回报模式。