It is always interesting, for example, the expression tree of the Lambda expression, which does the same:
Expression<Func<MyDecimal,int>> convert = m => (int)m;
Using the LinqPad tool link, we can check the conversion and see that we have the following:
Expression<Func<MyDecimal,int>> (type: Lambda)
|
+- UnaryExpression (type:Convert) - Convert(int, decimal)
|
+- UnaryExpression (type:Convert) - Convert(decmal, MyDecimal)
, decimal
int
, , Lambda
, .
, , - :
Expression.Assign(
Expression.Variable(typeof(int), "i"),
Expression.Convert(
Expression.Convert(
Expression.New(
typeof(MyDecimal).GetConstructor(new[] {typeof(decimal)}),
Expression.Convert(
Expression.Constant(1),
typeof(decimal)
)
),
typeof(decimal)),
typeof(int)
)
)
: