Why the following code throws an exception at runtime, whereas doing it in the traditional way compiles without problem?
var left = Expression.Constant(25d);
var right = Expression.Constant(20);
// Throws an InvalidOperationException!
var multiplyExpression = Expression.Multiply(left, right);
var multiply = 25d * 20;
Debug.WriteLine(multiply.ToString()); // Works normally!
I won't use Expression.Convert
since I can't determine exactly which expression should be converted.
Expression.Convert
- using type precedence rules to determine which side to convert. – Zea