In VisitNewArrayExpression, expression.Type.ElementType should be used instead of expression.Type.
In Remotion.Data.Linq.Backend.DetailParsing.ParserRegistry GetParsers(Type expressionType) must be refactored to take into account that
1) There exist new, Expression sub-types (e.g. MethodBinaryExpression)
2) The order of the parsers is no longer irrelevant
The following quick code fixes 1) to make tests green, BUT DOES NOT FIX 2) !
public IEnumerable<IParser> GetParsers(Type expressionType)
{
//return _parsers[expressionType];
foreach (var parser in _parsers)
{
if (parser.Key.IsAssignableFrom(expressionType))
}
throw new ParserException(string.Format("No parser to parse expression of type {0} found.",expressionType));
}
This change was made to improve .NET 4.0 compatibility and to enable double-dispatch visitor scenarios.
This feature provides a new ExtensionExpression class which is meant to be the base class for custom expression types:
class ExtensionExpression : Expression { ... public bool CanReduce { get; } public Expression Reduce(); public Expression ReduceAndCheck(); public void Accept (ExpressionTreeVisitor visitor); public void VisitChildren (ExpressionTreeVisitor visitor); }
The methods are equivalent to the new methods on .NET 4.0's expression type.
ExpressionTreeVisitor.VisitExpression is changed to first check the expression for assignability to ExtensionExpression. If assignment is possible, it calls ExtensionExpression.Accept, which can be implemented by custom expressions to dispatch to the right Visit method. E.g, SubQueryExpression would use this method to dispatch to VisitSubQueryExpression. The custom expression can also test for a specific visitor interface (e.g., ISubQueryExpressionVisitor). If no dedicated Visit method exists, the method dispatches to ExpressionTreeVisitor.VisitUnknownExpression.
ExpressionTreeVisitor.VisitUnknownExpression is changed to call VisitChildren on the expression if the expression is an ExtensionExpression. If it is not, it throws a NotSupportedException (as it does now).
As a separate feature, ThrowingExpressionTreeVisitor will get a new mode called "automatic reduce mode". In this mode, VisitUnknownExpression tests whether the expression can be reduced. If so, it reduces the expression and visits the result. An exception is only thrown when the expression is not reducible (or when the reduced expression cannot be handled). "Exact" mode corresponds to the current behavior - an exception is thrown (without an attempt for reduction) by default.