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

Lambda Expressions - Good code Red

1 Answer 57 Views
Code Analysis
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcus
Top achievements
Rank 1
Marcus asked on 20 Jan 2010, 01:48 AM
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

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 22 Jan 2010, 10:01 AM
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.
Tags
Code Analysis
Asked by
Marcus
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or