Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert WorkItemCollection to a List

I want to convert WorkItemCollection to a List<WorkItem>, so that I could convert it further into a dictionary. Here's the code so far:

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);
like image 786
John Stephen Avatar asked Feb 17 '14 06:02

John Stephen


2 Answers

testItemCollectionList = (from WorkItem mItem in testItemCollection select mItem).ToList();
like image 171
Sameer Avatar answered Nov 19 '22 20:11

Sameer


Since WorkItemCollection implements IEnumerable through ReadOnlyList, you should be able to use .Cast<WorkItem>() then directly convert to a Dictionary.

var testItemMapQuery = testItemCollection.Cast<WorkItem>()
                                         .ToDictionary(w => w, createItemFromQuery);
like image 7
tvanfosson Avatar answered Nov 19 '22 20:11

tvanfosson