本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionStatementSyntax.ToString方法的具体用法?C# ExpressionStatementSyntax.ToString怎么用?C# ExpressionStatementSyntax.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax
的用法示例。
在下文中一共展示了ExpressionStatementSyntax.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RewriteStatement
/// <summary>
/// Rewrites the raise statement.
/// </summary>
/// <param name="node">ExpressionStatementSyntax</param>
/// <returns>SyntaxNode</returns>
private SyntaxNode RewriteStatement(ExpressionStatementSyntax node)
{
var text = "{ " + node.ToString() + "return; }";
var rewritten = SyntaxFactory.ParseStatement(text);
rewritten = rewritten.WithTriviaFrom(node);
return rewritten;
}
示例2: AssignMethodReturnToReceiverAsync
private async Task<Document> AssignMethodReturnToReceiverAsync(CodeFixContext context, Document document, ExpressionStatementSyntax statement, string receiverName, CancellationToken c)
{
var rValueExpr = statement.ToString();
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
var memberAccess = root.FindNode(context.Span)?.FirstAncestorOrSelf<MemberAccessExpressionSyntax>();
var declaration = SyntaxFactory
.ParseStatement($"{receiverName} = {rValueExpr}");
var formattedDeclaration = declaration.WithTriviaFrom(statement);
// Replace the old statement with the block:
var newRoot = root.ReplaceNode((SyntaxNode)statement, formattedDeclaration);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
示例3: VisitExpressionStatement
public override void VisitExpressionStatement(ExpressionStatementSyntax node)
{
// TODO: Don't just emit the expression as-is. Need to process the nodes of the expression
Emit(node.ToString());
}
示例4: AssignMethodReturnToNewVariable
private async Task<Document> AssignMethodReturnToNewVariable(Document document, ExpressionStatementSyntax statement, CancellationToken c)
{
var rValueExpr = statement.ToString();
var semanticModel = await document.GetSemanticModelAsync();
var newVariable = FindAvailableVariableName("returnValue",
statement, semanticModel);
var declaration = SyntaxFactory.ParseStatement($"var {newVariable} = {rValueExpr}");
var formattedDeclaration = declaration.WithTriviaFrom(statement);
// Replace the old statement with the block:
var root = await document.GetSyntaxRootAsync();
var newRoot = root.ReplaceNode((SyntaxNode)statement, formattedDeclaration);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
示例5: VisitExpressionStatement
public override void VisitExpressionStatement(ExpressionStatementSyntax node)
{
_2JS.AppendLine(node.ToString());
base.VisitExpressionStatement(node);
}