this state is easier to go back to.

This commit is contained in:
David Lebée 2018-03-23 19:02:50 -05:00
parent 406290df78
commit 3fcb34522f

View File

@ -241,7 +241,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
return result; return result;
} }
internal static Expression InternalResolvePathExpression(int step, Expression param, List<string> parts, SelectCollectionHandling selectCollectionHandling, bool nullChecking) internal static Expression InternalResolvePathExpression(int step, Expression param, List<string> parts, SelectCollectionHandling selectCollectionHandling, bool nullChecking, Type nullCheckingType = null)
{ {
var isLast = parts.Count == 1; var isLast = parts.Count == 1;
var currentPart = parts.First(); var currentPart = parts.First();
@ -258,7 +258,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
// TODO: null checking here too. // TODO: null checking here too.
// should be easier then collection :=| // should be easier then collection :=|
ret = InternalResolvePathExpression(step + 1, memberExpression, parts.Skip(1).ToList(), selectCollectionHandling, nullChecking); ret = InternalResolvePathExpression(step + 1, memberExpression, parts.Skip(1).ToList(), selectCollectionHandling, nullChecking, nullCheckingType: nullCheckingType);
} }
else else
{ {
@ -276,15 +276,6 @@ namespace PoweredSoft.DynamicLinq.Helpers
ret = Expression.Call(typeof(Enumerable), "SelectMany", new Type[] { listGenericArgumentType, innerExpression.Type.GenericTypeArguments.First() }, memberExpression, lambda); ret = Expression.Call(typeof(Enumerable), "SelectMany", new Type[] { listGenericArgumentType, innerExpression.Type.GenericTypeArguments.First() }, memberExpression, lambda);
} }
if (nullChecking)
{
ret = Expression.Condition(
Expression.Equal(memberExpression, Expression.Constant(null)),
Expression.Constant(null, ret.Type),
ret
);
}
return ret; return ret;
} }
@ -297,7 +288,11 @@ namespace PoweredSoft.DynamicLinq.Helpers
public static Expression ResolvePathForExpression(ParameterExpression param, string path, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.Select, bool nullChecking = false) public static Expression ResolvePathForExpression(ParameterExpression param, string path, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.Select, bool nullChecking = false)
{ {
var parts = path.Split('.').ToList(); var parts = path.Split('.').ToList();
return InternalResolvePathExpression(1, param, parts, selectCollectionHandling, nullChecking); var notCheckingNullResult = InternalResolvePathExpression(1, param, parts, selectCollectionHandling, false);
if (!nullChecking)
return notCheckingNullResult;
throw new NotSupportedException("not yet done");
} }
public static ConstantExpression GetConstantSameAsLeftOperator(Expression member, object value) public static ConstantExpression GetConstantSameAsLeftOperator(Expression member, object value)
@ -522,10 +517,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
return result; return result;
} }
public static bool IsEnumerable(MemberExpression member) public static bool IsEnumerable(MemberExpression member) => IsEnumerable(member.Type);
{ public static bool IsEnumerable(Type type) => typeof(IEnumerable).IsAssignableFrom(type);
var ret = member.Type.FullName.StartsWith("System.Collection");
return ret;
}
} }
} }