13

I need a way to create an empty IOrderedEnumerable and IEnumerable>

//above IGrouping DynamicNode gets stripped out by stackoverflow :(

Reason: I create 3 empty list types (IOrdered, IGrouping, IEnumerable) then based on some other information (options a user specifies such as order by create date or group by month) I then call a function on it assigning a list of said type.

(short snippet)

//DOESNT WORK THIS IS THE PART I NEED
IEnumerable<DynamicNode> baseList = Enumerable.Empty<DynamicNode>();
IOrderedEnumerable<DynamicNode> orderedList =  (IOrderedEnumerable<DynamicNode>)Enumerable.Empty<DynamicNode>();
IEnumerable<IGrouping<string, DynamicNode>> groupedList = (IEnumerable<IGrouping<string, DynamicNode>>)Enumerable.Empty<DynamicNode>();
//ABOVE DOESNT WORK THIS IS THE PART I NEED

if (order)
    {
        if (group)
    {
        groupedList = returnGroupedOrderedList(nodeList, ascending, useFeatured, groupBy, orderBy);
    }
    else
    {
        orderedList = returnOrderedList(nodeList, ascending, useFeatured, orderBy);
    }
}

Anyone know how to do it?

ps If I haven't been clear enough please let me know how I can help you, help me :)

Thanks!

4

1 回答 1

20

第一个应该按原样工作:

IEnumerable<DynamicNode> baseList = Enumerable.Empty<DynamicNode>();

第二个应该有一个小技巧:

IOrderedEnumerable<DynamicNode> orderedList =
    Enumerable.Empty<DynamicNode>().OrderBy(x => 1);

第三个应该稍作改动:

IEnumerable<IGrouping<string, DynamicNode>> groupedList = 
    Enumerable.Empty<IGrouping<string, DynamicNode>>();
于 2013-04-16T09:11:52.523 回答