本文整理汇总了C#中ExpressionSyntax.GetLineNumber方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax.GetLineNumber方法的具体用法?C# ExpressionSyntax.GetLineNumber怎么用?C# ExpressionSyntax.GetLineNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionSyntax
的用法示例。
在下文中一共展示了ExpressionSyntax.GetLineNumber方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsStatementBody
/// <summary>
/// Converts the <paramref name="expression" /> body into a statement body.
/// </summary>
private static BlockSyntax AsStatementBody(IMethodSymbol methodSymbol, ExpressionSyntax expression)
{
StatementSyntax body;
if (methodSymbol.ReturnsVoid)
body = SyntaxFactory.ExpressionStatement(expression);
else
{
var returnStatement = SyntaxFactory.ReturnStatement(expression);
var returnKeyword = returnStatement.ReturnKeyword.WithTrailingSpace();
body = returnStatement.WithReturnKeyword(returnKeyword);
}
body = body.EnsureIndentation(expression).PrependLineDirective(expression.GetLineNumber()).AppendLineDirective(-1);
var block = SyntaxFactory.Block(body).PrependLineDirective(-1).AppendLineDirective(-1);
block = block.WithOpenBraceToken(block.OpenBraceToken.WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed));
block = block.WithCloseBraceToken(block.CloseBraceToken.WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed));
return block;
}