Skip to content

Commit 25b2ce9

Browse files
Single if statement
1 parent 7c293c6 commit 25b2ce9

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -270,31 +270,20 @@ _methodNode is VBSyntax.MethodBlockSyntax mb &&
270270
if (setMethodName != null) {
271271
if (lhs is InvocationExpressionSyntax ies) {
272272
ExpressionSyntax exprToReplace = ies.Expression;
273-
if (exprToReplace is MemberAccessExpressionSyntax {Name: IdentifierNameSyntax idn} maes) {
274-
var newName = SyntaxFactory.IdentifierName(setMethodName).WithTriviaFrom(idn);
275-
exprToReplace = maes.WithName(newName);
276-
277-
if (maes.Expression is ThisExpressionSyntax) {
278-
var skipParens = node.Left.SkipIntoParens();
279-
var isNonSelfQualified = skipParens is VBSyntax.MemberAccessExpressionSyntax {
280-
Expression: not VBSyntax.MeExpressionSyntax
281-
and not VBSyntax.MyClassExpressionSyntax
273+
if (exprToReplace is MemberAccessExpressionSyntax maes) {
274+
var newName = SyntaxFactory.IdentifierName(setMethodName).WithTriviaFrom(maes.Name);
275+
var stripThis = maes.Expression is ThisExpressionSyntax
276+
&& node.Left.SkipIntoParens() is not VBSyntax.MemberAccessExpressionSyntax {
277+
Expression: not (VBSyntax.MeExpressionSyntax or VBSyntax.MyClassExpressionSyntax)
282278
};
283-
if (!isNonSelfQualified) {
284-
exprToReplace = newName.WithTriviaFrom(maes);
285-
}
286-
}
287-
} else if (exprToReplace is IdentifierNameSyntax idn2) {
288-
var newName = SyntaxFactory.IdentifierName(setMethodName).WithTriviaFrom(idn2);
289-
exprToReplace = newName;
279+
exprToReplace = stripThis ? newName.WithTriviaFrom(maes) : maes.WithName(newName);
280+
} else if (exprToReplace is IdentifierNameSyntax) {
281+
exprToReplace = SyntaxFactory.IdentifierName(setMethodName).WithTriviaFrom(exprToReplace);
290282
}
291-
var newArg = SyntaxFactory.Argument(rhs);
292-
var newArgs = ies.ArgumentList.Arguments.Add(newArg);
293-
var newArgList = ies.ArgumentList.WithArguments(newArgs);
283+
var newArgList = ies.ArgumentList.AddArguments(SyntaxFactory.Argument(rhs));
294284
var newLhs = ies.WithExpression(exprToReplace).WithArgumentList(newArgList);
295-
var invokeAssignment = SyntaxFactory.ExpressionStatement(newLhs);
296285
var postAssign = GetPostAssignmentStatements(node);
297-
return postAssign.Insert(0, invokeAssignment);
286+
return postAssign.Insert(0, SyntaxFactory.ExpressionStatement(newLhs));
298287
}
299288
return SingleStatement(lhs);
300289
}

0 commit comments

Comments
 (0)