public LambdaExpressionSyntax ConvertLambdaExpression(CSS.AnonymousFunctionExpressionSyntax node, CS.CSharpSyntaxNode body, IEnumerable <ParameterSyntax> parameters, SyntaxTokenList modifiers) { var symbol = (IMethodSymbol)ModelExtensions.GetSymbolInfo(_semanticModel, node).Symbol; var parameterList = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters.Select(p => (Microsoft.CodeAnalysis.VisualBasic.Syntax.ParameterSyntax)p.Accept(_nodesVisitor)))); LambdaHeaderSyntax header; EndBlockStatementSyntax endBlock; SyntaxKind multiLineExpressionKind; SyntaxKind singleLineExpressionKind; bool isSub = symbol.ReturnsVoid; if (isSub) { header = SyntaxFactory.SubLambdaHeader(SyntaxFactory.List <AttributeListSyntax>(), ConvertModifiers(modifiers, TokenContext.Local), parameterList, null); endBlock = SyntaxFactory.EndBlockStatement(SyntaxKind.EndSubStatement, SyntaxFactory.Token(SyntaxKind.SubKeyword)); multiLineExpressionKind = SyntaxKind.MultiLineSubLambdaExpression; singleLineExpressionKind = SyntaxKind.SingleLineSubLambdaExpression; } else { header = CreateFunctionHeader(modifiers, parameterList, out endBlock, out multiLineExpressionKind); singleLineExpressionKind = SyntaxKind.SingleLineFunctionLambdaExpression; } SyntaxList <StatementSyntax> statements; if (body is CSS.BlockSyntax block) { statements = ConvertStatements(block.Statements); } else if (body.Kind() == CSSyntaxKind.ThrowExpression) { var csThrowExpression = (CSS.ThrowExpressionSyntax)body; var vbThrowExpression = (ExpressionSyntax)csThrowExpression.Expression.Accept(_nodesVisitor); var vbThrowStatement = SyntaxFactory.ThrowStatement(SyntaxFactory.Token(SyntaxKind.ThrowKeyword), vbThrowExpression); return(SyntaxFactory.MultiLineFunctionLambdaExpression(header, SyntaxFactory.SingletonList <StatementSyntax>(vbThrowStatement), endBlock)); } else { var stmt = GetStatementSyntax(body.Accept(_nodesVisitor), expression => isSub ? (StatementSyntax)SyntaxFactory.ExpressionStatement(expression) : SyntaxFactory.ReturnStatement(expression)); statements = InsertRequiredDeclarations(SyntaxFactory.SingletonList(stmt), body); } return(CreateLambdaExpression(singleLineExpressionKind, multiLineExpressionKind, header, statements, endBlock)); }
public bool ReturnsVoid(CSS.AnonymousFunctionExpressionSyntax node) { var symbol = (IMethodSymbol)_semanticModel.GetSymbolInfo(node).Symbol; return(symbol.ReturnsVoid); }