C# -> VB: Fix NRE from delegate with no parameters - fixes #50

This commit is contained in:
GrahamTheCoder 2018-03-16 08:45:48 +00:00
Родитель 4df901ac71
Коммит 56ee8d790b
2 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -1134,12 +1134,13 @@ End Function";
public override VisualBasicSyntaxNode VisitAnonymousMethodExpression(CSS.AnonymousMethodExpressionSyntax node)
{
return ConvertLambdaExpression(node, node.Block.Statements, node.ParameterList.Parameters, SyntaxFactory.TokenList(node.AsyncKeyword));
var parameterListParameters = node.ParameterList?.Parameters ?? Enumerable.Empty<CSS.ParameterSyntax>();// May have no parameter list
return ConvertLambdaExpression(node, node.Block.Statements, parameterListParameters, SyntaxFactory.TokenList(node.AsyncKeyword));
}
public override VisualBasicSyntaxNode VisitSimpleLambdaExpression(CSS.SimpleLambdaExpressionSyntax node)
{
return ConvertLambdaExpression(node, node.Body, SyntaxFactory.SingletonSeparatedList(node.Parameter), SyntaxFactory.TokenList(node.AsyncKeyword));
return ConvertLambdaExpression(node, node.Body, new[] {node.Parameter}, SyntaxFactory.TokenList(node.AsyncKeyword));
}
public override VisualBasicSyntaxNode VisitParenthesizedLambdaExpression(CSS.ParenthesizedLambdaExpressionSyntax node)
@ -1147,7 +1148,7 @@ End Function";
return ConvertLambdaExpression(node, node.Body, node.ParameterList.Parameters, SyntaxFactory.TokenList(node.AsyncKeyword));
}
LambdaExpressionSyntax ConvertLambdaExpression(CSS.AnonymousFunctionExpressionSyntax node, object block, SeparatedSyntaxList<CSS.ParameterSyntax> parameters, SyntaxTokenList modifiers)
LambdaExpressionSyntax ConvertLambdaExpression(CSS.AnonymousFunctionExpressionSyntax node, object block, IEnumerable<CSS.ParameterSyntax> parameters, SyntaxTokenList modifiers)
{
var symbol = ModelExtensions.GetSymbolInfo(semanticModel, node).Symbol as IMethodSymbol;
var parameterList = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters.Select(p => (ParameterSyntax)p.Accept(TriviaConvertingVisitor))));

Просмотреть файл

@ -199,6 +199,9 @@ End Class");
{
TestConversionCSharpToVisualBasic(@"class TestClass
{
private static Action<int> m_Event1 = delegate { };
void TestMethod()
{
var test = delegate(int a) { return a * 2 };
@ -206,6 +209,9 @@ End Class");
test(3);
}
}", @"Class TestClass
Private Shared m_Event1 As Action(Of Integer) = Function()
End Function
Private Sub TestMethod()
Dim test = Function(ByVal a As Integer) a * 2
test(3)