well advancing but not done yet :)
This commit is contained in:
@@ -16,10 +16,58 @@ namespace PoweredSoft.DynamicLinq.ConsoleApp
|
||||
{
|
||||
var type = typeof(Dal.Pocos.Author);
|
||||
var param = Expression.Parameter(type);
|
||||
var path = "Posts.Comments.Id";
|
||||
var parts = ExpressionPathPart.Split(param, "Posts.Comments.Id");
|
||||
|
||||
var parts = ExpressionPathPart.Break(param, "Posts.Comments.Id");
|
||||
// add the last part.
|
||||
var parent = parts.Last();
|
||||
var toListType = parent.GetToListType();
|
||||
parts.Add(new ExpressionPathPart
|
||||
{
|
||||
ParentExpression = parent.PartExpression,
|
||||
PartExpression = Expression.Call(typeof(Enumerable), "ToList", new[] { toListType }, parent.ParentExpression)
|
||||
});
|
||||
|
||||
var result = CreateSelectExpressionFromParts(parts, SelectCollectionHandling.Flatten, SelectNullHandling.New);
|
||||
}
|
||||
|
||||
public static Expression CreateSelectExpressionFromParts(List<ExpressionPathPart> parts,
|
||||
SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.LeaveAsIs,
|
||||
SelectNullHandling nullChecking = SelectNullHandling.LeaveAsIs)
|
||||
{
|
||||
Type nullHandlingRightType = null;
|
||||
Expression nullHandlingNullValue = null;
|
||||
|
||||
if (nullChecking != SelectNullHandling.LeaveAsIs)
|
||||
{
|
||||
nullHandlingRightType = parts.Last().PartExpression.Type;
|
||||
nullHandlingNullValue = nullChecking == SelectNullHandling.Default
|
||||
? Expression.Default(nullHandlingRightType) as Expression
|
||||
: Expression.New(nullHandlingRightType) as Expression;
|
||||
}
|
||||
|
||||
// reversed :)
|
||||
var reversedCopy = parts.Select(t => t).ToList();
|
||||
reversedCopy.Reverse();
|
||||
|
||||
Expression ret = null;
|
||||
reversedCopy.ForEach(t =>
|
||||
{
|
||||
if (t.IsParentGenericEnumerable())
|
||||
{
|
||||
var lambda = t.GetLambdaExpression();
|
||||
var parentGenericType = t.ParentGenericEnumerableType();
|
||||
if (selectCollectionHandling == SelectCollectionHandling.LeaveAsIs || !t.IsGenericEnumerable())
|
||||
ret = Expression.Call(typeof(Enumerable), "Select", new Type[] { parentGenericType, t.PartExpression.Type }, t.ParentExpression, lambda);
|
||||
else
|
||||
ret = Expression.Call(typeof(Enumerable), "SelectMany", new Type[] { parentGenericType, t.GenericEnumerableType() }, t.ParentExpression, lambda);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = t.PartExpression;
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user