Skip to content

Commit 33e39cb

Browse files
Check for null argument list earlier - fixes #171
1 parent 5690325 commit 33e39cb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

ICSharpCode.CodeConverter/CSharp/NodesVisitor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ public override CSharpSyntaxNode VisitConstructorBlock(VBSyntax.ConstructorBlock
723723

724724
var ctor = (node.Statements.FirstOrDefault() as VBSyntax.ExpressionStatementSyntax)?.Expression as VBSyntax.InvocationExpressionSyntax;
725725
var ctorExpression = ctor?.Expression as VBSyntax.MemberAccessExpressionSyntax;
726-
var ctorArgs = (ArgumentListSyntax)ctor?.ArgumentList.Accept(TriviaConvertingVisitor);
726+
var ctorArgs = (ArgumentListSyntax)ctor?.ArgumentList?.Accept(TriviaConvertingVisitor) ?? SyntaxFactory.ArgumentList();
727727

728728
IEnumerable<VBSyntax.StatementSyntax> statements;
729729
ConstructorInitializerSyntax ctorCall;
@@ -732,10 +732,10 @@ public override CSharpSyntaxNode VisitConstructorBlock(VBSyntax.ConstructorBlock
732732
ctorCall = null;
733733
} else if (ctorExpression.Expression is VBSyntax.MyBaseExpressionSyntax) {
734734
statements = node.Statements.Skip(1);
735-
ctorCall = SyntaxFactory.ConstructorInitializer(SyntaxKind.BaseConstructorInitializer, ctorArgs ?? SyntaxFactory.ArgumentList());
735+
ctorCall = SyntaxFactory.ConstructorInitializer(SyntaxKind.BaseConstructorInitializer, ctorArgs);
736736
} else if (ctorExpression.Expression is VBSyntax.MeExpressionSyntax || ctorExpression.Expression is VBSyntax.MyClassExpressionSyntax) {
737737
statements = node.Statements.Skip(1);
738-
ctorCall = SyntaxFactory.ConstructorInitializer(SyntaxKind.ThisConstructorInitializer, ctorArgs ?? SyntaxFactory.ArgumentList());
738+
ctorCall = SyntaxFactory.ConstructorInitializer(SyntaxKind.ThisConstructorInitializer, ctorArgs);
739739
} else {
740740
statements = node.Statements;
741741
ctorCall = null;

Tests/CSharp/NamespaceLevelTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,25 @@ Inherits System.IO.InvalidDataException
275275
}");
276276
}
277277

278+
[Fact]
279+
public void ClassInheritsClassWithNoParenthesesOnBaseCall()
280+
{
281+
// Moving where the base call appears confuses the auto comment tester
282+
TestConversionVisualBasicToCSharpWithoutComments(@"Public Class DataSet1
283+
Inherits Global.System.Data.DataSet
284+
Public Sub New()
285+
MyBase.New
286+
End Sub
287+
End Class",
288+
@"public class DataSet1 : global::System.Data.DataSet
289+
{
290+
public DataSet1() : base()
291+
{
292+
}
293+
}
294+
");
295+
}
296+
278297
[Fact]
279298
public void MultilineDocComment()
280299
{

0 commit comments

Comments
 (0)