我对IAsyncCursor
如何实现GetEnumerator()和Dispose()?
public sealed class DeferredResultCollection<TResult> : IEnumerable<TResult>, IDisposable
{
private readonly IAsyncCursor<TResult> _asyncCursor;
public DeferredResultCollection(IAsyncCursor<TResult> asyncCursor)
{
_asyncCursor = asyncCursor;
}
public IEnumerator<TResult> GetEnumerator()
{
for (; _asyncCursor.MoveNextAsync().Result;)
{
foreach (var result in _asyncCursor.Current)
{
yield return result;
}
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Dispose()
{
if (_asyncCursor != null)
{
_asyncCursor.Dispose();
}
}
}
我在C#中新以下包装类,我想补充新的构造IList<TResult>
并实施新的方法为IList<TResult>
GetEnumerator()
和Dispose()
。这个怎么做?请帮帮我。