Refactored the traversal, ishelper, etc... methods to be extension methods on IPublishedContent so now all of these methods are available on the Typed object not just the dynamic object which makes a whole lot more sense... and you can have intellisense.
Updated DynamicPublishedContent's methods to just proxy calls to the new extension methods so that all of the logic is contained in one place. Added new GetRootDocuments to the IPublishedContentStore since we need this in order to get the root list of documents for many of these methods. Fixed an issue with the DynamicNode to IPublishedContent converter. Fixed many of the failing unit tests.
This commit is contained in:
@@ -2,18 +2,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Dynamics
|
||||
{
|
||||
internal static class DynamicPublishedContentListOrdering
|
||||
{
|
||||
|
||||
private static TOut Reduce<TOut>(Func<DynamicPublishedContent, TOut> func, DynamicPublishedContent publishedContent)
|
||||
private static TOut Reduce<TOut>(Func<DynamicPublishedContentBase, TOut> func, DynamicPublishedContentBase publishedContent)
|
||||
{
|
||||
var value = func(publishedContent);
|
||||
while (value is Func<DynamicPublishedContent, TOut>)
|
||||
while (value is Func<DynamicPublishedContentBase, TOut>)
|
||||
{
|
||||
value = (value as Func<DynamicPublishedContent, TOut>)(publishedContent);
|
||||
value = (value as Func<DynamicPublishedContentBase, TOut>)(publishedContent);
|
||||
}
|
||||
//when you're sorting a list of properties
|
||||
//and one of those properties doesn't exist, it will come back as DynamicNull
|
||||
@@ -37,209 +38,209 @@ namespace Umbraco.Core.Dynamics
|
||||
}
|
||||
return (TOut)value;
|
||||
}
|
||||
public static IOrderedQueryable<DynamicPublishedContent> OrderBy(object source, object key)
|
||||
internal static IOrderedQueryable<DynamicPublishedContentBase> OrderBy(object source, object key)
|
||||
{
|
||||
IEnumerable<DynamicPublishedContent> typedSource = source as IEnumerable<DynamicPublishedContent>;
|
||||
IEnumerable<DynamicPublishedContentBase> typedSource = source as IEnumerable<DynamicPublishedContentBase>;
|
||||
LambdaExpression lambda = key as LambdaExpression;
|
||||
//if the lambda we have returns an actual property, not a dynamic one,
|
||||
//then the TOut of the func will be the actual type, not object
|
||||
//Func<DynamicNode, object> func = (Func<DynamicNode, object>)lambda.Compile();
|
||||
var func = lambda.Compile();
|
||||
var TOut = func.GetType().GetGenericArguments()[1];
|
||||
IOrderedQueryable<DynamicPublishedContent> result = null;
|
||||
if (TOut == typeof(Func<DynamicPublishedContent, object>))
|
||||
IOrderedQueryable<DynamicPublishedContentBase> result = null;
|
||||
if (TOut == typeof(Func<DynamicPublishedContentBase, object>))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderBy(x => Reduce<object>(func as Func<DynamicPublishedContent, object>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderBy(x => Reduce<object>(func as Func<DynamicPublishedContentBase, object>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(object))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderBy(x => Reduce<object>(func as Func<DynamicPublishedContent, object>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderBy(x => Reduce<object>(func as Func<DynamicPublishedContentBase, object>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(bool))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderBy(x => Reduce<bool>(func as Func<DynamicPublishedContent, bool>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderBy(x => Reduce<bool>(func as Func<DynamicPublishedContentBase, bool>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(decimal))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderBy(x => Reduce<decimal>(func as Func<DynamicPublishedContent, decimal>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderBy(x => Reduce<decimal>(func as Func<DynamicPublishedContentBase, decimal>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(int))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderBy(x => Reduce<int>(func as Func<DynamicPublishedContent, int>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderBy(x => Reduce<int>(func as Func<DynamicPublishedContentBase, int>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(string))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderBy(x => Reduce<string>(func as Func<DynamicPublishedContent, string>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderBy(x => Reduce<string>(func as Func<DynamicPublishedContentBase, string>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(DateTime))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderBy(x => Reduce<DateTime>(func as Func<DynamicPublishedContent, DateTime>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderBy(x => Reduce<DateTime>(func as Func<DynamicPublishedContentBase, DateTime>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static IOrderedQueryable<DynamicPublishedContent> ThenBy(object source, object key)
|
||||
internal static IOrderedQueryable<DynamicPublishedContentBase> ThenBy(object source, object key)
|
||||
{
|
||||
IOrderedQueryable<DynamicPublishedContent> typedSource = source as IOrderedQueryable<DynamicPublishedContent>;
|
||||
IOrderedQueryable<DynamicPublishedContentBase> typedSource = source as IOrderedQueryable<DynamicPublishedContentBase>;
|
||||
LambdaExpression lambda = key as LambdaExpression;
|
||||
var func = lambda.Compile();
|
||||
var TOut = func.GetType().GetGenericArguments()[1];
|
||||
IOrderedQueryable<DynamicPublishedContent> result = null;
|
||||
if (TOut == typeof(Func<DynamicPublishedContent, object>))
|
||||
IOrderedQueryable<DynamicPublishedContentBase> result = null;
|
||||
if (TOut == typeof(Func<DynamicPublishedContentBase, object>))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenBy(x => Reduce<object>(func as Func<DynamicPublishedContent, object>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenBy(x => Reduce<object>(func as Func<DynamicPublishedContentBase, object>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(object))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenBy(x => Reduce<object>(func as Func<DynamicPublishedContent, object>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenBy(x => Reduce<object>(func as Func<DynamicPublishedContentBase, object>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(bool))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenBy(x => Reduce<bool>(func as Func<DynamicPublishedContent, bool>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenBy(x => Reduce<bool>(func as Func<DynamicPublishedContentBase, bool>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(decimal))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenBy(x => Reduce<decimal>(func as Func<DynamicPublishedContent, decimal>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenBy(x => Reduce<decimal>(func as Func<DynamicPublishedContentBase, decimal>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(int))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenBy(x => Reduce<int>(func as Func<DynamicPublishedContent, int>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenBy(x => Reduce<int>(func as Func<DynamicPublishedContentBase, int>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(string))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenBy(x => Reduce<string>(func as Func<DynamicPublishedContent, string>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenBy(x => Reduce<string>(func as Func<DynamicPublishedContentBase, string>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(DateTime))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenBy(x => Reduce<DateTime>(func as Func<DynamicPublishedContent, DateTime>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenBy(x => Reduce<DateTime>(func as Func<DynamicPublishedContentBase, DateTime>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static IOrderedQueryable<DynamicPublishedContent> OrderByDescending(object source, object key)
|
||||
internal static IOrderedQueryable<DynamicPublishedContentBase> OrderByDescending(object source, object key)
|
||||
{
|
||||
IEnumerable<DynamicPublishedContent> typedSource = source as IEnumerable<DynamicPublishedContent>;
|
||||
IEnumerable<DynamicPublishedContentBase> typedSource = source as IEnumerable<DynamicPublishedContentBase>;
|
||||
LambdaExpression lambda = key as LambdaExpression;
|
||||
var func = lambda.Compile();
|
||||
var TOut = func.GetType().GetGenericArguments()[1];
|
||||
IOrderedQueryable<DynamicPublishedContent> result = null;
|
||||
if (TOut == typeof(Func<DynamicPublishedContent, object>))
|
||||
IOrderedQueryable<DynamicPublishedContentBase> result = null;
|
||||
if (TOut == typeof(Func<DynamicPublishedContentBase, object>))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderByDescending(x => Reduce<object>(func as Func<DynamicPublishedContent, object>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderByDescending(x => Reduce<object>(func as Func<DynamicPublishedContentBase, object>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(object))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderByDescending(x => Reduce<object>(func as Func<DynamicPublishedContent, object>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderByDescending(x => Reduce<object>(func as Func<DynamicPublishedContentBase, object>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(bool))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderByDescending(x => Reduce<bool>(func as Func<DynamicPublishedContent, bool>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderByDescending(x => Reduce<bool>(func as Func<DynamicPublishedContentBase, bool>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(decimal))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderByDescending(x => Reduce<decimal>(func as Func<DynamicPublishedContent, decimal>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderByDescending(x => Reduce<decimal>(func as Func<DynamicPublishedContentBase, decimal>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(int))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderByDescending(x => Reduce<int>(func as Func<DynamicPublishedContent, int>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderByDescending(x => Reduce<int>(func as Func<DynamicPublishedContentBase, int>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(string))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderByDescending(x => Reduce<string>(func as Func<DynamicPublishedContent, string>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderByDescending(x => Reduce<string>(func as Func<DynamicPublishedContentBase, string>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(DateTime))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.OrderByDescending(x => Reduce<DateTime>(func as Func<DynamicPublishedContent, DateTime>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.OrderByDescending(x => Reduce<DateTime>(func as Func<DynamicPublishedContentBase, DateTime>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static IOrderedQueryable<DynamicPublishedContent> ThenByDescending(object source, object key)
|
||||
internal static IOrderedQueryable<DynamicPublishedContentBase> ThenByDescending(object source, object key)
|
||||
{
|
||||
IOrderedQueryable<DynamicPublishedContent> typedSource = source as IOrderedQueryable<DynamicPublishedContent>;
|
||||
IOrderedQueryable<DynamicPublishedContentBase> typedSource = source as IOrderedQueryable<DynamicPublishedContentBase>;
|
||||
LambdaExpression lambda = key as LambdaExpression;
|
||||
var func = lambda.Compile();
|
||||
var TOut = func.GetType().GetGenericArguments()[1];
|
||||
IOrderedQueryable<DynamicPublishedContent> result = null;
|
||||
if (TOut == typeof(Func<DynamicPublishedContent, object>))
|
||||
IOrderedQueryable<DynamicPublishedContentBase> result = null;
|
||||
if (TOut == typeof(Func<DynamicPublishedContentBase, object>))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenByDescending(x => Reduce<object>(func as Func<DynamicPublishedContent, object>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenByDescending(x => Reduce<object>(func as Func<DynamicPublishedContentBase, object>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(object))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenByDescending(x => Reduce<object>(func as Func<DynamicPublishedContent, object>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenByDescending(x => Reduce<object>(func as Func<DynamicPublishedContentBase, object>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(bool))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenByDescending(x => Reduce<bool>(func as Func<DynamicPublishedContent, bool>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenByDescending(x => Reduce<bool>(func as Func<DynamicPublishedContentBase, bool>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(decimal))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenByDescending(x => Reduce<decimal>(func as Func<DynamicPublishedContent, decimal>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenByDescending(x => Reduce<decimal>(func as Func<DynamicPublishedContentBase, decimal>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(int))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenByDescending(x => Reduce<int>(func as Func<DynamicPublishedContent, int>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenByDescending(x => Reduce<int>(func as Func<DynamicPublishedContentBase, int>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(string))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenByDescending(x => Reduce<string>(func as Func<DynamicPublishedContent, string>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenByDescending(x => Reduce<string>(func as Func<DynamicPublishedContentBase, string>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
if (TOut == typeof(DateTime))
|
||||
{
|
||||
result = (IOrderedQueryable<DynamicPublishedContent>)typedSource
|
||||
.ThenByDescending(x => Reduce<DateTime>(func as Func<DynamicPublishedContent, DateTime>, x))
|
||||
result = (IOrderedQueryable<DynamicPublishedContentBase>)typedSource
|
||||
.ThenByDescending(x => Reduce<DateTime>(func as Func<DynamicPublishedContentBase, DateTime>, x))
|
||||
.AsQueryable();
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user