Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an empty IOrderedEnumerable<DynamicNode> and IEnumerable<IGrouping<string, DynamicNode>>

Tags:

c#

razor

umbraco

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!

like image 441
user2265321 Avatar asked Apr 16 '13 09:04

user2265321


1 Answers

The first should work as is:

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

The second should work with a little trick:

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

The third should work with a little change:

IEnumerable<IGrouping<string, DynamicNode>> groupedList = 
    Enumerable.Empty<IGrouping<string, DynamicNode>>();
like image 138
Daniel Hilgarth Avatar answered Sep 29 '22 17:09

Daniel Hilgarth