Skip to content

Commit

Permalink
Converts "default" keyword to "Nothing" keyword - fixes #428
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamTheCoder committed Mar 11, 2020
1 parent 35dc08c commit 68ce59b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### C# -> VB

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

## [7.9.0] - 2020-02-27

Expand Down
6 changes: 4 additions & 2 deletions CodeConverter/VB/NodesVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,10 @@ public override VisualBasicSyntaxNode VisitParameter(CSS.ParameterSyntax node)

public override VisualBasicSyntaxNode VisitLiteralExpression(CSS.LiteralExpressionSyntax node)
{
// now this looks somehow hacky... is there a better way?
if (node.IsKind(CS.SyntaxKind.StringLiteralExpression) && node.Token.Text.StartsWith("@", StringComparison.Ordinal)) {
if (node.IsKind(CS.SyntaxKind.DefaultLiteralExpression)) {
return VisualBasicSyntaxFactory.NothingExpression;
// This looks somehow hacky... is there a better way to check whether it's a verbatim string?
} else if (node.IsKind(CS.SyntaxKind.StringLiteralExpression) && node.Token.Text.StartsWith("@", StringComparison.Ordinal)) {
return SyntaxFactory.StringLiteralExpression(
SyntaxFactory.StringLiteralToken(
node.Token.Text.Substring(1),
Expand Down
24 changes: 24 additions & 0 deletions Tests/VB/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ End Sub
End Class");
}

[Fact]
public async Task DefaultLiteralExpression()
{
await TestConversionCSharpToVisualBasic(@"public class DefaultLiteralExpression {
public bool Foo {
get {
return (Bar == default);
}
}
public int Bar;
}", @"Public Class DefaultLiteralExpression
Public ReadOnly Property Foo As Boolean
Get
Return Bar = Nothing
End Get
End Property
Public Bar As Integer
End Class");
}

[Fact]
public async Task IsNullExpression()
{
Expand Down

0 comments on commit 68ce59b

Please sign in to comment.