// Adds Value = ... and ClassID = ... member decorations to all NewExpressions for MetaID within the given expression. private Expression <Func <IDatabaseResultRow, object> > AddNewMetaIDMemberDecoration(Expression <Func <IDatabaseResultRow, object> > expression) { return(AdHocExpressionVisitor.TransformAndRetainType( expression, expr => { var newExpression = expr as NewExpression; if (newExpression != null && newExpression.Constructor.DeclaringType == typeof(MetaID)) { return Expression.New( newExpression.Constructor, newExpression.Arguments, new[] { typeof(MetaID).GetProperty("Value"), typeof(MetaID).GetProperty("ClassID") }); } return expr; })); }
private Expression ReplaceConvertExpressionMarker(Expression simplifiedExpectedInMemoryProjection) { return(AdHocExpressionVisitor.Transform(simplifiedExpectedInMemoryProjection, expr => { var methodCallExpression = expr as MethodCallExpression; if (methodCallExpression != null && methodCallExpression.Method.Name == "ConvertExpressionMarker") { var conversionMethodCall = methodCallExpression.Arguments.Single() as MethodCallExpression; if (conversionMethodCall == null || conversionMethodCall.Object != null || conversionMethodCall.Arguments.Count != 1) { throw new InvalidOperationException( "The argument to ConvertExpressionMarker must be a MethodCallExpression to a static method with a single argument."); } return Expression.Convert(conversionMethodCall.Arguments.Single(), conversionMethodCall.Type, conversionMethodCall.Method); } return expr; })); }