private static IEnumerable <PropertyPath> MatchPropertyAccessList( this LambdaExpression lambdaExpression, Func <Expression, Expression, PropertyPath> propertyMatcher) { NewExpression newExpression = lambdaExpression.Body.RemoveConvert() as NewExpression; if (newExpression != null) { ParameterExpression parameterExpression = lambdaExpression.Parameters.Single <ParameterExpression>(); IEnumerable <PropertyPath> propertyPaths = newExpression.Arguments.Select <Expression, PropertyPath>((Func <Expression, PropertyPath>)(a => propertyMatcher(a, (Expression)parameterExpression))).Where <PropertyPath>((Func <PropertyPath, bool>)(p => p != (PropertyPath)null)); if (propertyPaths.Count <PropertyPath>() == newExpression.Arguments.Count <Expression>()) { if (!newExpression.HasDefaultMembersOnly(propertyPaths)) { return((IEnumerable <PropertyPath>)null); } return(propertyPaths); } } PropertyPath propertyPath = propertyMatcher(lambdaExpression.Body, (Expression)lambdaExpression.Parameters.Single <ParameterExpression>()); if (!(propertyPath != (PropertyPath)null)) { return((IEnumerable <PropertyPath>)null); } return((IEnumerable <PropertyPath>) new PropertyPath[1] { propertyPath }); }
static IEnumerable <PropertyPath> MatchPropertyAccessList(this LambdaExpression lambdaExpression, Func <Expression, Expression, PropertyPath> propertyMatcher) { NewExpression newExpression = lambdaExpression.Body.RemoveConvert() as NewExpression; if (newExpression != null) { var parameterExpression = lambdaExpression.Parameters.Single <ParameterExpression>(); IEnumerable <PropertyPath> enumerable = from a in newExpression.Arguments select propertyMatcher(a, parameterExpression) into p where p != null select p; if (enumerable.Count() == newExpression.Arguments.Count) { if (!newExpression.HasDefaultMembersOnly(enumerable)) { return(null); } return(enumerable); } } var propertyPath = propertyMatcher(lambdaExpression.Body, lambdaExpression.Parameters.Single <ParameterExpression>()); if (propertyPath == null) { return(null); } return(propertyPath.Cast <PropertyPath>()); }