我想将WorkItemCollection
转换为List<WorkItem>
,以便我可以将其进一步转换为dictionary
。这是迄今为止的代码:
var testItemCollectionList = new List<WorkItem>();
WorkItemCollection testItemCollection;
Query query = new Query(project.Store, "Select [Title] From WorkItems", testResults.Select(item => item.TargetId).ToArray());
var car = query.BeginQuery();
testItemCollection = query.EndQuery(car);
testItemCollectionList = ???;
var testItemMapQuery = testItemCollectionList.ToDictionary(w => w, createItemFromQuery);
答案 0 :(得分:7)
由于WorkItemCollection
通过IEnumerable
实施ReadOnlyList
,您应该可以使用.Cast<WorkItem>()
,然后直接转换为Dictionary
。
var testItemMapQuery = testItemCollection.Cast<WorkItem>()
.ToDictionary(w => w, createItemFromQuery);
答案 1 :(得分:6)
testItemCollectionList = (from WorkItem mItem in testItemCollection select mItem).ToList();