Lambda Expressions - Good code Red

2 posts, 0 answers
  1. Marcus
    Marcus avatar
    15 posts
    Member since:
    Dec 2007

    Posted 19 Jan 2010 Link to this post

    Hi there,

    We have a somewhat complex method in our solution which uses Lambda Expressions to provide type-safe reflection.
    Any calls to the method come up as invalid code, although it compiles and functions perfectly.

    The method signature is:

    void LogChangeTrackingEvent<T, X>(T object, Expression<Func<T, X>> propTransform, X newValue) where T : ITrackable;

    So for example, to change the property MyProperty of object myObj of type MyClass, you'd call:


    LogChangeTrackingEvent(myObj, o => o.MyProperty, newValue); 

    No need to delve into the plumbing (splits up the Lambda expression in order to provide an automated tracking log), but this comes up with an error in JustCode.

    An instance of type double? cannot be returned by a function of type double.

    Note that in this instance MyProperty is of type double? and newValue is of type double.


    Let me know if you need some more information on this, or if you can identify why this is showing up as bad code in JustCode.


    Thanks!


    Marcus

  2. Kaloyan
    Admin
    Kaloyan avatar
    82 posts

    Posted 22 Jan 2010 Link to this post

    Hello Marcus,

    Thanks for the detailed description of the situation. We were able to reproduce that and added it to our product backlog for a near-future fix. We awarded you some telerik points for the detailed description of the issue. For the time being a workaround for this particular case might be to insert the types of the parameters as generic arguments to the function:

    .LogChangeTrackingEvent<MyClass, double?>(myObj, o => o.MyProperty, newValue)

     

    Stay tuned for updates on the matter.

    Regards,
    Kaloyan
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
Back to Top