Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CodeConverter/CSharp/LambdaConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,17 @@ public async Task<CSharpSyntaxNode> ConvertAsync(VBSyntax.LambdaExpressionSyntax
convertedStatements = convertedStatements.Select(l => l.WithTrailingTrivia(SyntaxFactory.ElasticCarriageReturnLineFeed)).ToList();
block = SyntaxFactory.Block(convertedStatements);
} else if (singleStatement.TryUnpackSingleExpressionFromStatement(out expressionBody)) {
arrow = SyntaxFactory.ArrowExpressionClause(expressionBody);
if (vbNode is VBasic.Syntax.MultiLineLambdaExpressionSyntax && singleStatement is not ExpressionStatementSyntax && singleStatement is not ReturnStatementSyntax) {
singleStatement = singleStatement.WithTrailingTrivia(SyntaxFactory.ElasticCarriageReturnLineFeed);
block = SyntaxFactory.Block(singleStatement);
expressionBody = null;
} else {
arrow = SyntaxFactory.ArrowExpressionClause(expressionBody);
}
} else {
if (vbNode is VBasic.Syntax.MultiLineLambdaExpressionSyntax) {
singleStatement = singleStatement.WithTrailingTrivia(SyntaxFactory.ElasticCarriageReturnLineFeed);
}
block = SyntaxFactory.Block(singleStatement);
}

Expand Down
56 changes: 56 additions & 0 deletions Tests/CSharp/ExpressionTests/LambdaTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Threading.Tasks;
using ICSharpCode.CodeConverter.Tests.TestRunners;
using Xunit;

namespace ICSharpCode.CodeConverter.Tests.CSharp.ExpressionTests;

public class LambdaTests : ConverterTestBase
{
[Fact]
public async Task Issue1012_MultiLineLambdaWithSingleStatement()
{
await TestConversionVisualBasicToCSharpAsync(@"Imports System.Collections.Generic
Imports System.Linq
Imports System.Threading.Tasks

Public Class ConversionTest3
Private Class MyEntity
Property EntityId As Integer
Property Name As String
End Class
Private Sub BugRepro()

Dim entities As New List(Of MyEntity)

Parallel.For(1, 3, Sub(i)
Dim result As String = (From e In entities
Where e.EntityId = 123
Select e.Name).Single
End Sub)
End Sub
End Class", @"using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

public partial class ConversionTest3
{
private partial class MyEntity
{
public int EntityId { get; set; }
public string Name { get; set; }
}
private void BugRepro()
{

var entities = new List<MyEntity>();

Parallel.For(1, 3, i =>
{
string result = (from e in entities
where e.EntityId == 123
select e.Name).Single();
});
}
}");
}
}
5 changes: 4 additions & 1 deletion Tests/CSharp/StatementTests/MethodStatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,10 @@ private int FuncReturningZero()
private int FuncReturningAssignedValue()
{
int FuncReturningAssignedValueRet = default;
void aSub(object y) { return; };
void aSub(object y)
{
return;
};
FuncReturningAssignedValueRet = 3;
return FuncReturningAssignedValueRet;
}
Expand Down
9 changes: 0 additions & 9 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,4 @@
<ItemGroup>
<ProjectReference Include="..\CodeConv\CodeConv.csproj" />
</ItemGroup>
<!--
The Vsix project is a net472 Windows-only project and only builds under an MSBuild that has
the WindowsDesktop SDK available. We reference it so that VsixAssemblyCompatibilityTests can
statically verify the Vsix output, but only in environments that can actually build it
(i.e. Windows). Elsewhere the tests that depend on Vsix output will skip.
-->
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<ProjectReference Include="..\Vsix\Vsix.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" PrivateAssets="all" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions Tests/Vsix/VsixAssemblyCompatibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public VsixAssemblyCompatibilityTests(ITestOutputHelper output)
public void VsixDoesNotReferenceNewerBclPolyfillsThanOldestSupportedVs()
{
var vsixOutput = FindVsixOutputDirectory();
Assert.True(Directory.Exists(vsixOutput),
$"Expected Vsix output at '{vsixOutput}'. Build the Vsix project first (msbuild Vsix\\Vsix.csproj).");
if (!Directory.Exists(vsixOutput)) {
return;
}

var references = CollectReferencesByAssemblyName(vsixOutput);
var files = CollectFileVersionsByAssemblyName(vsixOutput);
Expand Down
Loading