本文整理汇总了C#中BlockSyntax.Update方法的典型用法代码示例。如果您正苦于以下问题:C# BlockSyntax.Update方法的具体用法?C# BlockSyntax.Update怎么用?C# BlockSyntax.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockSyntax
的用法示例。
在下文中一共展示了BlockSyntax.Update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReformatBodyAsMultipleLines
private static BlockSyntax ReformatBodyAsMultipleLines(BlockSyntax body, SyntaxTrivia indentation, SyntaxTrivia indentationStatements)
{
SyntaxTriviaList reformattedOpenBraceTrailingTrivia;
SyntaxTriviaList reformattedCloseBraceLeadingTrivia;
SyntaxList<StatementSyntax> newStatements;
if (body.Statements.Count > 0)
{
var statements = new List<StatementSyntax>();
foreach (var statement in body.Statements)
{
var reformattedStatement = statement
.WithLeadingTrivia(ReformatTriviaListNoLeadingSpace(statement.GetLeadingTrivia()).Insert(0, indentationStatements))
.WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(statement.GetTrailingTrivia()).Add(SyntaxFactory.CarriageReturnLineFeed));
statements.Add(reformattedStatement);
}
newStatements = SyntaxFactory.List<StatementSyntax>().AddRange(statements);
reformattedOpenBraceTrailingTrivia = ReformatTriviaListNoTrailingSpace(body.OpenBraceToken.TrailingTrivia);
reformattedCloseBraceLeadingTrivia = ReformatTriviaListNoLeadingSpace(body.CloseBraceToken.LeadingTrivia);
}
else
{
var triviaBetweenBraces = TriviaHelper.MergeTriviaLists(body.OpenBraceToken.TrailingTrivia, body.CloseBraceToken.LeadingTrivia);
reformattedOpenBraceTrailingTrivia = ReformatTriviaListNoTrailingSpace(triviaBetweenBraces);
newStatements = body.Statements;
reformattedCloseBraceLeadingTrivia = SyntaxFactory.TriviaList();
}
var newOpenBraceToken = body.OpenBraceToken
.WithLeadingTrivia(ReformatTriviaListNoLeadingSpace(body.OpenBraceToken.LeadingTrivia).Insert(0, indentation))
.WithTrailingTrivia(reformattedOpenBraceTrailingTrivia.Add(SyntaxFactory.CarriageReturnLineFeed));
var newCloseBraceToken = body.CloseBraceToken
.WithLeadingTrivia(reformattedCloseBraceLeadingTrivia.Insert(0, indentation))
.WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(body.CloseBraceToken.TrailingTrivia).Add(SyntaxFactory.CarriageReturnLineFeed));
return body.Update(newOpenBraceToken, newStatements, newCloseBraceToken);
}
示例2: VisitBlock
protected override SyntaxNode VisitBlock(BlockSyntax node)
{
var results = base.VisitBlock (node);
node = results as BlockSyntax;
if (node == null)
return results;
List<StatementSyntax> statements = new List<StatementSyntax> (node.Statements.Count + 4);
foreach (StatementSyntax statement in node.Statements)
{
bool loop = statement.HasAnnotation (this.isLoop);
if (loop)
statements.Add (BeginLoopStatement);
if (this.loopLevel > 0)
{
if (statement is ContinueStatementSyntax || statement is BreakStatementSyntax)
statements.Add (EndInsideLoopStatement);
else if (statement is ReturnStatementSyntax && ((ReturnStatementSyntax)statement).ExpressionOpt == null)
statements.Add (ReturnStatement);
}
statements.Add (statement);
var es = statement as ExpressionStatementSyntax;
if (es != null)
{
var postfixUnary = es.ChildNodes().OfType<PostfixUnaryExpressionSyntax>().FirstOrDefault();
if (postfixUnary != null)
{
var name = postfixUnary.Operand as IdentifierNameSyntax;
if (name != null)
statements.Add (Syntax.ExpressionStatement (GetLogExpression (name.PlainName, name.PlainName)));
}
}
if (loop)
statements.Add (EndLoopStatement);
}
return node.Update (node.OpenBraceToken, Syntax.List<StatementSyntax> (statements), node.CloseBraceToken);
}
示例3: ReformatBodyAsSingleLine
private static BlockSyntax ReformatBodyAsSingleLine(BlockSyntax body)
{
var newOpenBraceToken = body.OpenBraceToken
.WithLeadingTrivia(ReformatTriviaList(body.OpenBraceToken.LeadingTrivia))
.WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(body.OpenBraceToken.TrailingTrivia));
SyntaxList<StatementSyntax> newStatements;
if (body.Statements.Count > 0)
{
var reformattedStatement = body.Statements[0]
.WithLeadingTrivia(ReformatTriviaList(body.Statements[0].GetLeadingTrivia()))
.WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(body.Statements[0].GetTrailingTrivia()));
newStatements = SyntaxFactory.List<StatementSyntax>().Add(reformattedStatement);
}
else
{
newStatements = body.Statements;
}
var newCloseBraceToken = body.CloseBraceToken
.WithLeadingTrivia(ReformatTriviaList(body.CloseBraceToken.LeadingTrivia))
.WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(body.CloseBraceToken.TrailingTrivia).Add(SyntaxFactory.CarriageReturnLineFeed));
return body.Update(newOpenBraceToken, newStatements, newCloseBraceToken);
}
示例4: VisitBlock
protected override SyntaxNode VisitBlock(BlockSyntax node)
{
var results = base.VisitBlock (node);
node = results as BlockSyntax;
if (node == null)
return results;
List<StatementSyntax> statements = new List<StatementSyntax> (node.Statements.Count + 4);
foreach (StatementSyntax statement in node.Statements)
{
bool loop = statement.HasAnnotation (this.isLoop);
if (loop)
statements.Add (BeginLoopStatement);
if (this.loopLevel > 0)
{
if (statement is ContinueStatementSyntax || statement is BreakStatementSyntax)
statements.Add (EndInsideLoopStatement);
else if (statement is ReturnStatementSyntax && ((ReturnStatementSyntax)statement).ExpressionOpt == null)
statements.Add (ReturnStatement);
}
statements.Add (statement);
if (loop)
statements.Add (EndLoopStatement);
}
return node.Update (node.OpenBraceToken, Syntax.List<StatementSyntax> (statements), node.CloseBraceToken);
}