diff --git a/UseConditionalOperatorAnalyzer/UseConditionalOperatorAnalyzer.Vsix/source.extension.vsixmanifest b/UseConditionalOperatorAnalyzer/UseConditionalOperatorAnalyzer.Vsix/source.extension.vsixmanifest
index 22ecbfa..b996447 100644
--- a/UseConditionalOperatorAnalyzer/UseConditionalOperatorAnalyzer.Vsix/source.extension.vsixmanifest
+++ b/UseConditionalOperatorAnalyzer/UseConditionalOperatorAnalyzer.Vsix/source.extension.vsixmanifest
@@ -10,6 +10,7 @@
+
diff --git a/UseConditionalOperatorAnalyzer/UseConditionalOperatorAnalyzer/CodeFixProvider.cs b/UseConditionalOperatorAnalyzer/UseConditionalOperatorAnalyzer/CodeFixProvider.cs
index fd428ef..3eb4672 100644
--- a/UseConditionalOperatorAnalyzer/UseConditionalOperatorAnalyzer/CodeFixProvider.cs
+++ b/UseConditionalOperatorAnalyzer/UseConditionalOperatorAnalyzer/CodeFixProvider.cs
@@ -54,6 +54,35 @@ private static TNode CreateNodeWithSourceFormatting(SyntaxNode sourceNode
.WithTrailingTrivia(sourceNode.GetTrailingTrivia());
}
+ private static ExpressionSyntax ExtractSimpleAssignmentRight(AssignmentExpressionSyntax assignment)
+ {
+ switch (assignment.CSharpKind())
+ {
+ case SyntaxKind.AddAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.AddExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.SubtractAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.MultiplyAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.MultiplyExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.DivideAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.DivideExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.ModuloAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.ModuloExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.AndAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.AndAssignmentExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.OrAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.OrAssignmentExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.ExclusiveOrAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.ExclusiveOrExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.LeftShiftAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.LeftShiftExpression, assignment.Left, assignment.Right);
+ case SyntaxKind.RightShiftAssignmentExpression:
+ return SyntaxFactory.BinaryExpression(SyntaxKind.RightShiftExpression, assignment.Left, assignment.Right);
+ default:
+ return assignment.Right;
+ }
+ }
+
private static LocalDeclarationStatementSyntax CreateVarDeclaration(string symbolName, ExpressionSyntax expression)
{
return
@@ -78,8 +107,8 @@ private async static Task ApplyAssignmentCodeFix(Document sourceDocu
SyntaxFactory
.ConditionalExpression(
ApplyFormatting(SyntaxFactory.ParenthesizedExpression(ifStatement.Condition)),
- ApplyFormatting(truePartExpr.Right),
- ApplyFormatting(falsePartExpr.Right));
+ ApplyFormatting(ExtractSimpleAssignmentRight(truePartExpr)),
+ ApplyFormatting(ExtractSimpleAssignmentRight(falsePartExpr)));
var assignmentExpr =
SyntaxFactory