From 288bbe7b917bc6accdb27edc3f9aaf98fac3d74f Mon Sep 17 00:00:00 2001 From: "agrath@gmail.com" Date: Mon, 13 Jun 2011 09:12:11 -0200 Subject: [PATCH] Added OrderBy to Grouping so the nested lists can be ordered by (supports single property only but does handle desc) You can control the Group order by manipulating the source list order. Groups will be enumerated in the order they occur. --- .../RazorDynamicNode/Grouping.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/umbraco.MacroEngines.Juno/RazorDynamicNode/Grouping.cs b/umbraco.MacroEngines.Juno/RazorDynamicNode/Grouping.cs index 7082944562..13600e165c 100644 --- a/umbraco.MacroEngines.Juno/RazorDynamicNode/Grouping.cs +++ b/umbraco.MacroEngines.Juno/RazorDynamicNode/Grouping.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; +using System.Dynamic; namespace umbraco.MacroEngines { - public class Grouping : IGrouping + public class Grouping : IGrouping where T : DynamicObject { public K Key { get; set; } public IEnumerable Elements; @@ -19,6 +20,40 @@ namespace umbraco.MacroEngines { return (IEnumerator)GetEnumerator(); } + + public IOrderedEnumerable OrderBy(string ordering) + { + bool descending = false; + if (ordering.IndexOf(" descending", StringComparison.CurrentCultureIgnoreCase) >= 0) + { + ordering = ordering.Replace(" descending", ""); + descending = true; + } + if (ordering.IndexOf(" desc", StringComparison.CurrentCultureIgnoreCase) >= 0) + { + ordering = ordering.Replace(" desc", ""); + descending = true; + } + + if (!descending) + { + return Elements.OrderBy(item => + { + object key = null; + (item as DynamicObject).TryGetMember(new DynamicQueryableGetMemberBinder(ordering, false), out key); + return key; + }); + } + else + { + return Elements.OrderByDescending(item => + { + object key = null; + (item as DynamicObject).TryGetMember(new DynamicQueryableGetMemberBinder(ordering, false), out key); + return key; + }); + } + } } }