我有一个包装类用于处理IAsyncCursor
,它返回IEnumerable<TResult>
我的程序可以从两个地方获取项目:
IEnumerable<TResult> GetItems()
{
List<TResult> fromA = fromA();
IEnumerable<TResult> fromB = fromB();
var result = fromA.Concat(fromB).ToList();
return result;
}
但我不想在内存中存储result
,因为太昂贵了。
我想把GetItems()
的返回结果更改为返回ResultCollection
,并且具有调用Dispose()
的能力。
因此,我需要更改fromA()
和fromB()
方法的返回结果为ResultCollection
,如下所示:
ResultCollection<TResult> GetItems()
{
ResultCollection<TResult> fromA = fromA(); // wrap List<TResult> to ResultCollection
ResultCollection<TResult> fromB = fromB(); // return collection that I can dispose when I need
return new ResultCollection<TResult>(fromA.Concat(fromB).ToList());
}
我需要如何更改我的ResultCollection
以存储List
构造函数? 我需要这个新类符合所有的OOP
和SOLID
原则。
我不需要在ResultCollection
中再添加另一个构造函数,例如:
public ResultCollection(IList<TResult> list)
{
_list = list;
}
return new DeferredResultCollection<TResult>(fromA(), fromB())
了。 - poke