Skip to content

Commit

Permalink
Exit Property now returns value assigned to return variable - fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamTheCoder committed Dec 10, 2023
1 parent db071f5 commit 186c758
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### VB -> C#

* Exit Property now returns value assigned to return variable [#1051](https://github.com/icsharpcode/CodeConverter/issues/1051)
* Avoid stack overflow for very deeply nested binary expressions [#1033](https://github.com/icsharpcode/CodeConverter/issues/1033)
* Omit special VB conversions within expression trees [#930](https://github.com/icsharpcode/CodeConverter/issues/930) [#316](https://github.com/icsharpcode/CodeConverter/issues/316)
* Support CData [#1032](https://github.com/icsharpcode/CodeConverter/issues/1032)
Expand Down
2 changes: 1 addition & 1 deletion CodeConverter/CSharp/DeclarationNodeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ public override async Task<CSharpSyntaxNode> VisitAccessorBlock(VBSyntax.Accesso
var ancestoryPropertyBlock = node.GetAncestor<VBSyntax.PropertyBlockSyntax>();
var containingPropertyStmt = ancestoryPropertyBlock?.PropertyStatement;
var csReturnVariableOrNull = CommonConversions.GetRetVariableNameOrNull(node);
var convertedStatements = SyntaxFactory.Block(await ConvertMethodBodyStatementsAsync(node, node.Statements, isIterator));
var convertedStatements = SyntaxFactory.Block(await ConvertMethodBodyStatementsAsync(node, node.Statements, isIterator, csReturnVariableOrNull));
var body = WithImplicitReturnStatements(node, convertedStatements, csReturnVariableOrNull);
var attributes = await CommonConversions.ConvertAttributesAsync(node.AccessorStatement.AttributeLists);
var modifiers = CommonConversions.ConvertModifiers(node, node.AccessorStatement.Modifiers, TokenContext.Local);
Expand Down
57 changes: 57 additions & 0 deletions Tests/CSharp/StatementTests/StatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,63 @@ private IEnumerable<int> TestMethod(int number)
yield return i;
yield break;
}
}");
}

[Fact]
public async Task SetterReturnAsync()
{
await TestConversionVisualBasicToCSharpAsync(@"Public ReadOnly Property Prop() As Object
Get
Try
Prop = New Object
Exit Property
Catch ex As Exception
End Try
End Get
End Property
Public Function Func() As Object
Try
Func = New Object
Exit Function
Catch ex As Exception
End Try
End Function", @"
internal partial class SurroundingClass
{
public object Prop
{
get
{
object PropRet = default;
try
{
PropRet = new object();
return PropRet;
}
catch (Exception ex)
{
}
return PropRet;
}
}
public object Func()
{
object FuncRet = default;
try
{
FuncRet = new object();
return FuncRet;
}
catch (Exception ex)
{
}
return FuncRet;
}
}");
}
}

0 comments on commit 186c758

Please sign in to comment.