Bug 10717 - Some Auto-Fix regarding control flow:
Summary: Some Auto-Fix regarding control flow:
Status: RESOLVED INVALID
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: 4.0
Hardware: PC Windows
: Normal enhancement
Target Milestone: ---
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-02-27 02:11 UTC by Ciprian Khlud
Modified: 2013-02-27 09:42 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 INVALID

Description Ciprian Khlud 2013-02-27 02:11:55 UTC
I will use a more compact description with a motivation behind the way auto-fix should work in this way:

Input A: "Invert if and simplify else block" 
$if (condition)
{
   instr1;...; instrN;//a block with one or more instructions
}
else
{//block curly braces can be or can not be here
  continue|break|return;
}
When applied, becomes:
if(!condition)
  continue|break|return;
instr1;...; instrN;

Note: all pieces seem to be in place, it needs to be a composite of: Invert If, Remove Redundant Else; Remove Redundant Block

Input B: Convert to correct type

 "double c = 3.5;
  float fc $= c;"
When applied, becomes:
 "double c = 3.5;
  float fc = (float)c;"

Other similar case:
"
enum MyEnum{Field0, Field1}
var enumValue = MyEnum.Field1;
int intEnum $= enumValue;
"
When applied, becomes:
int intEnum $= (int)enumValue;

Typical conversions are:
- from different lengths of ints (byte, uint8, etc.)
- double to float
- enums to int and int to enum;

Input C: Convert to direct method call

class MainClass
{
	delegate void OnClick(int data);
	OnClick Click;

	static void Display(int data)
	{ Console.WriteLine(data);}

	public static void Main ()
	{
		var inst = new MainClass ();
		inst.Click += i$=>{Display(i);};
	}
}


When applied, becomes:
class MainClass
{
	delegate void OnClick(int data);
	OnClick Click;

	static void Display(int data)
	{ Console.WriteLine(data);}

	public static void Main ()
	{
		var inst = new MainClass ();
		inst.Click += Display;
	}
}
so: if Click has the same signature with Display and there is just one method in the block, and the lambda calls with the same parameters the method, the lambda can be simplified.

Input D: "Remove redundant paranthesis" in lambdas:
$(i) => ... 
can be simplified to: 
i=> ...
It works for 1 parameter method
Comment 1 Mike Krüger 2013-02-27 07:29:47 UTC
Can you do me a favor and break individual action requests into several reports - this makes it easier to keep track of each action.

I think we have C :) (but not in 4.0)
Comment 2 Ciprian Khlud 2013-02-27 07:32:17 UTC
Sure, I will, also for previous bugs. (I mean the ones that you said that are possible to be done). I will do it like in 4 hours from now.
Comment 3 Mike Krüger 2013-02-27 09:42:02 UTC
ok closing that bug then