When the computed expression body has a call to a method that takes an enum as an argument, an invalid operation exception is thrown because it tries to pass the integer value instead of the typed enum one.
public class Foo
{
public Decimal Value { get; set; }
[Computed]
public Decimal RoundedValue
{
get
{
return Decimal.Round(Value, 3, MidpointRounding.AwayFromZero);
}
}
}
public void Should_be_able_to_decompile_the_rounded_value()
{
var roundedValues = Enumerable.Range(1,10)
.Select(x => new Foo {Value =123.4561m})
.AsQueryable()
.Select(x => x.RoundedValue)
.Decompile();
roundedValues.Distinct().Count().ShouldBe(2);
roundedValues.ShouldContain(123.456m);
roundedValues.ShouldContain(123.457m);
}
System.ArgumentException
Expression of type 'System.Int32' cannot be used for parameter of type 'System.MidpointRounding' of method 'System.Decimal Round(System.Decimal, Int32, System.MidpointRounding)'
at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection`1& arguments)
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
at DelegateDecompiler.Processor.BuildMethodCallExpression(MethodInfo m, Address instance, Expression[] arguments)
at DelegateDecompiler.Processor.Call(ProcessorState state, MethodInfo m)
at DelegateDecompiler.Processor.Process()
at DelegateDecompiler.Processor.Process(VariableInfo[] locals, IList`1 args, Instruction instruction, Type returnType)
at DelegateDecompiler.MethodBodyDecompiler.Decompile()
at DelegateDecompiler.DecompileExtensions.<>c__DisplayClass1.<Decompile>b__0(MethodInfo m)
at DelegateDecompiler.Cache`2.GetOrAdd(TKey key, Func`2 func)
at DelegateDecompiler.DecompileExtensions.Decompile(MethodInfo method)
at DelegateDecompiler.DecompileExpressionVisitor.Decompile(MethodInfo method, Expression instance, IList`1 arguments)
at DelegateDecompiler.DecompileExpressionVisitor.VisitMember(MemberExpression node)
at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at DelegateDecompiler.DecompileExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at DelegateDecompiler.DecompiledQueryProvider.CreateQuery[TElement](Expression expression)
at DelegateDecompiler.DecompileExtensions.Decompile[T](IQueryable`1 self)