change expression return type

5 posts, 0 answers
  1. Dilbert
    Dilbert avatar
    3 posts
    Member since:
    Apr 2012

    Posted 07 May 2012 Link to this post

    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!
  2. Jarred Froman
    Jarred Froman avatar
    57 posts
    Member since:
    Aug 2008

    Posted 11 May 2012 Link to this post

    We are experiencing a similar problem as well.  Is there any update on this?

    Thanks
  3. DevCraft banner
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 May 2012 Link to this post

    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 >>

  5. Jarred Froman
    Jarred Froman avatar
    57 posts
    Member since:
    Aug 2008

    Posted 14 May 2012 Link to this post

    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!
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 May 2012 Link to this post

    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 >>

Back to Top
DevCraft banner