private Expression CreateMemberAccessComparison (ExpressionType expressionType, NewExpression newExpression, Expression otherExpression)
{
// The ReSharper warning is wrong - newExpression.Members can be null
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if (newExpression.Members == null || newExpression.Members.Count == 0)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
{
var message = string.Format (
"Compound values can only be compared if the respective constructor invocation has members associated with it. Expressions: '{0}', '{1}'",
FormattingExpressionTreeVisitor.Format (newExpression),
FormattingExpressionTreeVisitor.Format (otherExpression));
throw new NotSupportedException (message);
}
var combinedComparison = newExpression.Arguments
.Select ((arg, i) => (Expression) Expression.MakeBinary (expressionType, arg, GetMemberExpression (newExpression.Members[i], otherExpression)))
.Aggregate ((previous, current) => CombineComparisons (previous, current, expressionType, newExpression, otherExpression));
return PartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees (combinedComparison);
}