将IReliableDictionary转换为IList [英] Convert IReliableDictionary to IList
本文介绍了将IReliableDictionary转换为IList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个IReliableDictionary,需要将字典中的项目带入IList以从我可靠的服务中退回.
I have an IReliableDictionary and need to take the items in the dictionary and move them in to an IList to return from my reliable service.
似乎我无法执行任何类型的.ToList,所以我确定我无法正确处理它.
It seems I can't do a .ToList of any kind, so I'm sure I'm approaching it wrong.
public async Task<IList<CustomerOrderItem>> GetOrdersAsync()
{
IReliableDictionary<CustomerOrderItemId, CustomerOrderItem> orderItems =
await this.StateManager.GetOrAddAsync<IReliableDictionary<CustomerOrderItemId, CustomerOrderItem>>(CustomerOrderItemDictionaryName);
Dictionary<KeyValuePair<CustomerOrderItemId, CustomerOrderItem>, KeyValuePair<CustomerOrderItemId, CustomerOrderItem>> items = orderItems.ToDictionary(v => v);
IList<CustomerOrderItem> list = orderItems.ToList(); ???
...
}
关于如何从字典中取出项目并将其放入列表的任何想法?
Any ideas on how to take the items from the dictionary and put them in to the list?
推荐答案
IReliableDictionary(就像IDictionary一样)是IEnumerable键值对,因此您可以这样操作:
IReliableDictionary (just like an IDictionary) is IEnumerable of key value pairs, so you can go this way:
public async Task<IList<CustomerOrderItem>> GetOrdersAsync()
{
IReliableDictionary<CustomerOrderItemId, CustomerOrderItem> orderItems =
await this.StateManager.GetOrAddAsync<IReliableDictionary<CustomerOrderItemId, CustomerOrderItem>>(CustomerOrderItemDictionaryName);
var list = orderItems.Select(kvp => kvp.Value).ToList();
return list;
}
这篇关于将IReliableDictionary转换为IList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文