Priority
Normal
Type
Bug 
State
Fixed 
Assignee
Andrey Simanovsky 
Subsystem
No subsystem 
Affected versions
Fixed in
Fixed in build
Next build 
Build
262
Fixed in build
264
  • Submitted by   Erwin Derksen
    3 years ago (02 Oct 2006 14:10)
  • Updated by Erwin Derksen
    3 years ago (24 Oct 2006 18:12)
  • Jira: RSRP-29230
    (history, comments)

RSRP-29230

"Convert to conditional operator" converts to erroneous code

0
Version: VS2005

Given the following code:
	public bool IsEersteProduct
	{
		get
		{
			if (Pakket.GeselecteerdeProducten.Count > 0)
			{
				if (Pakket.GeselecteerdeProducten[0].PakketIndex == HuidigProductIndex)
				{
					return true;
				}
			}
			return false;
		}
	}

I wanted to convert this to a simple "get { return condition1 && condition2; }" using the context actions from resharper. Placing the cursor on the 2nd if, I get 3 context actions, amongst which "Convert to conditional operator". This operation results in:
	public bool IsEersteProduct
	{
		get
		{
			if (Pakket.GeselecteerdeProducten.Count > 0)
			{
				return Pakket.GeselecteerdeProducten[0].PakketIndex == HuidigProductIndex ? true : false;
			}
		}
	}

This code does not the same as the above code, it even contains a syntax error (return statement is missing) and thus is an incorrect refactoring.

Note 1: first merging the 2 if's and then "convert to conditional operator" does the trick.

Note 2: in case you are converting a boolean expression, like this one, you could as well remove the "? true ; false" part as well.


Issue was closed
Comments (0)
 
History (0)
 
Links
 
Issue has no comments