RefactoringEssentials icon indicating copy to clipboard operation
RefactoringEssentials copied to clipboard

?: Expression bug

Open FickoDeLux opened this issue 8 years ago • 1 comments

I have:

enum From
{
	Bottom,
	Top,
	Left,
	Right
}

void UpdateAdvanced(decimal wert, string nudname){
	decimal h = 0;
	if ((From)DGV.Rows[0].Cells[2].Value != From.Top) {
		DGV.Rows[0].Cells[1].Value = h - wert;
	}
	else {
		DGV.Rows[0].Cells[1].Value = wert;
	}
}

and this is what I am getting after ?: conversion:

	DGV.Rows[0].Cells[1].Value = (From)DGV.Rows[0].Cells[2].Value != From.Top ? (System.Object)h - wert : (object)wert;

I don't know where this "(System.Object)" or "(Object)" came from.

FickoDeLux avatar Feb 23 '17 09:02 FickoDeLux

Well seems like ConvertIfStatementToConditionalTernaryExpressionCodeRefactoringProvider generates explicit cast expression if target and ternary operator types are not equal and does not check if impilicit conversion exists. Should be considered as bug.

AndrewBoklashko avatar Feb 23 '17 14:02 AndrewBoklashko