Skip to content

Commit 68ce59b

Browse files
Converts "default" keyword to "Nothing" keyword - fixes #428
1 parent 35dc08c commit 68ce59b

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4141

4242
### C# -> VB
4343

44+
* Converts "default" keyword to "Nothing" keyword [#428](https://github.com/icsharpcode/CodeConverter/issues/428)
4445

4546
## [7.9.0] - 2020-02-27
4647

CodeConverter/VB/NodesVisitor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,10 @@ public override VisualBasicSyntaxNode VisitParameter(CSS.ParameterSyntax node)
820820

821821
public override VisualBasicSyntaxNode VisitLiteralExpression(CSS.LiteralExpressionSyntax node)
822822
{
823-
// now this looks somehow hacky... is there a better way?
824-
if (node.IsKind(CS.SyntaxKind.StringLiteralExpression) && node.Token.Text.StartsWith("@", StringComparison.Ordinal)) {
823+
if (node.IsKind(CS.SyntaxKind.DefaultLiteralExpression)) {
824+
return VisualBasicSyntaxFactory.NothingExpression;
825+
// This looks somehow hacky... is there a better way to check whether it's a verbatim string?
826+
} else if (node.IsKind(CS.SyntaxKind.StringLiteralExpression) && node.Token.Text.StartsWith("@", StringComparison.Ordinal)) {
825827
return SyntaxFactory.StringLiteralExpression(
826828
SyntaxFactory.StringLiteralToken(
827829
node.Token.Text.Substring(1),

Tests/VB/ExpressionTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ End Sub
8080
End Class");
8181
}
8282

83+
[Fact]
84+
public async Task DefaultLiteralExpression()
85+
{
86+
await TestConversionCSharpToVisualBasic(@"public class DefaultLiteralExpression {
87+
88+
public bool Foo {
89+
get {
90+
return (Bar == default);
91+
}
92+
}
93+
94+
public int Bar;
95+
96+
}", @"Public Class DefaultLiteralExpression
97+
Public ReadOnly Property Foo As Boolean
98+
Get
99+
Return Bar = Nothing
100+
End Get
101+
End Property
102+
103+
Public Bar As Integer
104+
End Class");
105+
}
106+
83107
[Fact]
84108
public async Task IsNullExpression()
85109
{

0 commit comments

Comments
 (0)