History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: RSRP-29230
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Normal Normal
Assignee: Andrey Simanovsky
Reporter: Erwin Derksen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ReSharper

"Convert to conditional operator" converts to erroneous code

Created: 02 Oct 06 14:10   Updated: 24 Oct 06 18:12
Component/s: None
Fix Version/s: 2.0.2
Security Level: Everybody (All jira users)

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 262
Fixed in build: 264


 Description  « Hide
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.



 All   Comments   Work Log   Change History      Sort Order:
Andrey Simanovsky - 04 Oct 06 20:46
Non-compilable code generation fixed. Smarter behavior of the action is fixed as a separate request in 3.0 version.