我有一个这样写的界面:
public interface IItemRetriever
{
public IAsyncEnumerable<string> GetItemsAsync();
}
Run Code Online (Sandbox Code Playgroud)
我想编写一个不返回任何项目的空实现,如下所示:
public class EmptyItemRetriever : IItemRetriever
{
public IAsyncEnumerable<string> GetItemsAsync()
{
// What do I put here if nothing is to be done?
}
}
Run Code Online (Sandbox Code Playgroud)
如果它是一个普通的 IEnumerable,我会return Enumerable.Empty<string>();,但我没有找到任何AsyncEnumerable.Empty<string>().
我发现这有效但很奇怪:
public async IAsyncEnumerable<string> GetItemsAsync()
{
await Task.CompletedTask;
yield break;
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?