Bug 10661 - Expression can be reduced to delegate code action should have varying severity
Summary: Expression can be reduced to delegate code action should have varying severity
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: Trunk
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-02-25 17:28 UTC by Bojan Rajkovic [MSFT]
Modified: 2013-02-26 04:16 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Bojan Rajkovic [MSFT] 2013-02-25 17:28:26 UTC
It would be nice if the expression can be reduced to delegate analysis "action" could have varying severity depending on the expression. 

In the case of simple expressions with direct delegate invocation, eg. Array.Sort (a, (b, c) => String.Compare (b, c));, it should be a warning-level, but for complex expressions that can nonetheless be reduced to a delegate, it should perhaps be a hint-level, as often, such complex expressions aren't suitable for rewriting as direct delegate invocations.
Comment 1 Mike Krüger 2013-02-25 18:45:44 UTC
varying severity for one issue is something that's atm not implemented not really plan of the todo list.

The severity is user controlled therefore it's not possible for the actions to change it (they can only make proposals :)).

Can you give me one of the 'complex expressions' that are worth beeing hint-level ?

If such thing exists (atm I should only propose very basic cases) I can add another rule with a different level for these cases.
Comment 2 Bojan Rajkovic [MSFT] 2013-02-25 20:34:12 UTC
So, as an example of a complex expression that CAN be converted to a delegate, but I would not want to, because it would look confusing, I have some code that looks like so:

return userCache.TryGetOrInsert ("user-" + userId + "-submissions", TimeSpan.FromMinutes (30), () => {
					return ComponentRepository.AllComponents.Where (c => c.UserID == userId).ToArray ();
				});

The lambda can be converted to an expression (it can be just ComponentRepository.AllComponents.Where (c => c.UserID == userId).ToArray), but it would look confusing to do so, as it no longer looks like a default value provider for a cache.
Comment 3 Mikayla Hutchinson [MSFT] 2013-02-25 22:38:34 UTC
Perhaps we could have two rules:

* trivial lambda *should* be reduced to delegate
  e.g. (x,y) => Foo (x,y)

* complex lambda *could* be reduced to delegate
  e.g. () = list.Where (x => x%2 == 0).ToArray ()
Comment 4 Mike Krüger 2013-02-26 03:27:30 UTC
hm, I think we just disable the 'complex' ones - they don't really look like they should be used that way.
Comment 5 Mike Krüger 2013-02-26 04:16:19 UTC
fixed