This is a migrated thread and some comments may be shown as answers.

change expression return type

4 Answers 95 Views
ExpressionEditor
This is a migrated thread and some comments may be shown as answers.
Dilbert
Top achievements
Rank 1
Dilbert asked on 07 May 2012, 12:12 PM
I am using Expression Editor control which uses Finances object which has nullable double fields (values): Debit (10), DebitYTD (100), Credit (20) and CreditYTD (200). In the formula, I want to do something like: Debit - Credit + DebitYTD - CreditYTD and this works fine and returns LinqExpression<Func<Finances, double?>> type. The problem is when I try to do something like 0.045 * (Debit) which returns a LinqExpression<Func<Finances, decimal>> type. How do I handle two different return types? Can I make expression control to always return LinqExpression<Func<Finances, double?>> type?

Update: This is a blocking issue for us, so I would request the telerik team to provide a solution or an approach on how to handle this scenario. Thanks!

4 Answers, 1 is accepted

Sort by
0
Jarred Froman
Top achievements
Rank 1
answered on 11 May 2012, 04:05 PM
We are experiencing a similar problem as well.  Is there any update on this?

Thanks
0
Dimitrina
Telerik team
answered on 14 May 2012, 10:27 AM
Hello,

For double constants you should use the exponential value: for example 0.0E+2. This should lead to result of type double.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jarred Froman
Top achievements
Rank 1
answered on 14 May 2012, 12:50 PM
Requiring the users to enter numbers in this way does not seem feasible.  Can a property be added to the control casting / requiring valid output type(s)?  This would make the control even more powerful by adding in an extra level of validation.

Thanks!
0
Dimitrina
Telerik team
answered on 14 May 2012, 01:37 PM
Hello,

 You can convert the expression that is returned from the editor. For example if your returned expression is 'decimalExpr', then you can convert it with a code similar to this one:

var newBody = Expression.Convert(decimalExpr.Body, typeof(double?));
var expr2 = Expression.Lambda(newBody, decimalExpr.Parameters) as Expression<Func<Finances, double?>>;
var func = expr2.Compile();

I hope that this is helpful.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ExpressionEditor
Asked by
Dilbert
Top achievements
Rank 1
Answers by
Jarred Froman
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or