本文整理汇总了C#中BlockSyntax类的典型用法代码示例。如果您正苦于以下问题:C# BlockSyntax类的具体用法?C# BlockSyntax怎么用?C# BlockSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockSyntax类属于命名空间,在下文中一共展示了BlockSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSpeculativeSemanticModelForMethodBody
private bool GetSpeculativeSemanticModelForMethodBody(SyntaxTreeSemanticModel parentModel, int position, BlockSyntax body, out SemanticModel speculativeModel)
{
position = CheckAndAdjustPosition(position);
var methodSymbol = (MethodSymbol)this.MemberSymbol;
// Strip off ExecutableCodeBinder (see ctor).
Binder binder = this.RootBinder;
do
{
if (binder is ExecutableCodeBinder)
{
binder = binder.Next;
break;
}
binder = binder.Next;
}
while (binder != null);
Debug.Assert(binder != null);
var executablebinder = new ExecutableCodeBinder(body, methodSymbol, binder ?? this.RootBinder);
var blockBinder = executablebinder.GetBinder(body).WithAdditionalFlags(GetSemanticModelBinderFlags());
speculativeModel = CreateSpeculative(parentModel, methodSymbol, body, blockBinder, position);
return true;
}
示例2: VisitBlock
public override SyntaxNode VisitBlock(BlockSyntax node)
{
BlockSyntax block = (BlockSyntax)base.VisitBlock(node);
SyntaxList<StatementSyntax> curList = new SyntaxList<StatementSyntax>();
Dictionary<string, SyntaxNode> replacements = new Dictionary<string, SyntaxNode>();
int numbering = 1;
foreach (var stmt in block.Statements)
{
SyntaxList<StatementSyntax> preList = new SyntaxList<StatementSyntax>();
var stm = stmt.ReplaceNodes(nodes: stmt.DescendantNodes().Reverse(), computeReplacementNode: (original, origWithReplacedDesc) =>
{
Console.WriteLine(origWithReplacedDesc.GetType() + ": " + origWithReplacedDesc);
if (origWithReplacedDesc.IsKind(SyntaxKind.InvocationExpression)
|| origWithReplacedDesc.IsKind(SyntaxKind.ObjectCreationExpression))
{
return SimplifyMethodAndConstructorInvocation(ref numbering, ref preList, original, origWithReplacedDesc);
}
return origWithReplacedDesc;
});
curList = curList.AddRange(preList);
curList = curList.Add(stm);
}
return block.WithStatements(curList);
}
示例3: MethodDeclaration
public static MethodDeclarationSyntax MethodDeclaration(
SyntaxList<AttributeListSyntax> attributeLists,
SyntaxTokenList modifiers,
TypeSyntax returnType,
ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
SyntaxToken identifier,
TypeParameterListSyntax typeParameterList,
ParameterListSyntax parameterList,
SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
BlockSyntax body,
SyntaxToken semicolonToken)
{
return SyntaxFactory.MethodDeclaration(
attributeLists,
modifiers,
default(SyntaxToken),
returnType,
explicitInterfaceSpecifier,
identifier,
typeParameterList,
parameterList,
constraintClauses,
body,
default(ArrowExpressionClauseSyntax),
semicolonToken);
}
示例4: VisitBlock
public override SyntaxNode VisitBlock(BlockSyntax node)
{
var results = base.VisitBlock (node);
if ((node = results as BlockSyntax) == null)
return results;
var list = new List<StatementSyntax>();
foreach (StatementSyntax statement in node.Statements)
{
var s = statement;
bool isloop = s.GetIsLoop();
if (isloop)
s = s.WithLeadingTrivia (s.GetLeadingTrivia().InsertComment (GetIdComment (this.blockIds.Dequeue())));
if (this.loopLevel > 0)
{
if (s is ContinueStatementSyntax || s is BreakStatementSyntax || s is ReturnStatementSyntax)
s = s.WithTrailingTrivia (s.GetTrailingTrivia().Prepend (GetIdComment()));
if (s is ReturnStatementSyntax && ((ReturnStatementSyntax)s).Expression == null)
s = s.WithTrailingTrivia (s.GetTrailingTrivia().Prepend (GetIdComment()));
}
list.Add (s);
if (isloop)
s = s.WithTrailingTrivia (s.GetTrailingTrivia().Prepend (GetIdComment()));
}
return node.WithStatements (Syntax.List<StatementSyntax> (list));
}
示例5: VisitBlock
public override void VisitBlock(BlockSyntax node)
{
if (_firstVisit)
{
_firstVisit = false;
foreach (var statement in node.Statements)
{
var leadingTabs = new string('\t', 3 + ClassDepth);
SyntaxNode formattedStatement = statement;
_code = formattedStatement.WithoutLeadingTrivia().WithTrailingTrivia().ToFullString().Replace(leadingTabs, string.Empty);
var nodeLine = formattedStatement.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line;
var line = _lineNumberOverride ?? nodeLine;
var codeBlocks = Regex.Split(_code, @"\/\*\*.*?\*\/", RegexOptions.Singleline)
.Select(b => b.TrimStart('\r', '\n').TrimEnd('\r', '\n', '\t'))
.Where(b => !string.IsNullOrEmpty(b) && b != ";")
.Select(b => new CodeBlock(b, line))
.ToList();
this.Blocks.AddRange(codeBlocks);
}
base.Visit(node);
}
}
示例6: ReformatBlockAndParent
private static SyntaxNode ReformatBlockAndParent(Document document, SyntaxNode syntaxRoot, BlockSyntax block)
{
var parentLastToken = block.OpenBraceToken.GetPreviousToken();
var parentEndLine = parentLastToken.GetEndLine();
var blockStartLine = block.OpenBraceToken.GetLine();
var newParentLastToken = parentLastToken;
if (parentEndLine == blockStartLine)
{
var newTrailingTrivia = parentLastToken.TrailingTrivia
.WithoutTrailingWhitespace()
.Add(SyntaxFactory.CarriageReturnLineFeed);
newParentLastToken = newParentLastToken.WithTrailingTrivia(newTrailingTrivia);
}
var parentNextToken = block.CloseBraceToken.GetNextToken();
var nextTokenLine = parentNextToken.GetLine();
var blockCloseLine = block.CloseBraceToken.GetEndLine();
var newParentNextToken = parentNextToken;
if (nextTokenLine == blockCloseLine)
{
newParentNextToken = newParentNextToken.WithLeadingTrivia(parentLastToken.LeadingTrivia);
}
var newBlock = ReformatBlock(document, block);
var rewriter = new BlockRewriter(parentLastToken, newParentLastToken, block, newBlock, parentNextToken, newParentNextToken);
var newSyntaxRoot = rewriter.Visit(syntaxRoot);
return newSyntaxRoot.WithoutFormatting();
}
示例7: generateRunTaskWrapper
private ArgumentSyntax generateRunTaskWrapper(BlockSyntax blocks, params ParameterSyntax[] parameters)
{
return Argument(taskBuilder
.ParenthesizedLambdaExpression(blocks)
.AddParameterListParameters(parameters)
);
}
示例8: RemoveRedundantBlock
private IEnumerable<StatementSyntax> RemoveRedundantBlock(BlockSyntax block)
{
// if block doesn't have any statement
if (block.Statements.Count == 0)
{
// either remove the block if it doesn't have any trivia, or return as it is if
// there are trivia attached to block
return (block.OpenBraceToken.GetAllTrivia().IsEmpty() && block.CloseBraceToken.GetAllTrivia().IsEmpty()) ?
SpecializedCollections.EmptyEnumerable<StatementSyntax>() : SpecializedCollections.SingletonEnumerable<StatementSyntax>(block);
}
// okay transfer asset attached to block to statements
var firstStatement = block.Statements.First();
var firstToken = firstStatement.GetFirstToken(includeZeroWidth: true);
var firstTokenWithAsset = block.OpenBraceToken.CopyAnnotationsTo(firstToken).WithPrependedLeadingTrivia(block.OpenBraceToken.GetAllTrivia());
var lastStatement = block.Statements.Last();
var lastToken = lastStatement.GetLastToken(includeZeroWidth: true);
var lastTokenWithAsset = block.CloseBraceToken.CopyAnnotationsTo(lastToken).WithAppendedTrailingTrivia(block.CloseBraceToken.GetAllTrivia());
// create new block with new tokens
block = block.ReplaceTokens(new[] { firstToken, lastToken }, (o, c) => (o == firstToken) ? firstTokenWithAsset : lastTokenWithAsset);
// return only statements without the wrapping block
return block.Statements;
}
示例9: WithBody
public static BaseMethodDeclarationSyntax WithBody(this BaseMethodDeclarationSyntax item, BlockSyntax body)
{
var cons = item as ConstructorDeclarationSyntax;
if (cons != null)
{
return cons.WithBody(body);
}
var conv = item as ConversionOperatorDeclarationSyntax;
if (conv != null)
{
return conv.WithBody(body);
}
var dest = item as DestructorDeclarationSyntax;
if (dest != null)
{
return dest.WithBody(body);
}
var meth = item as MethodDeclarationSyntax;
if (meth != null)
{
return meth.WithBody(body);
}
var oper = item as OperatorDeclarationSyntax;
if (oper != null)
{
return oper.WithBody(body);
}
throw new ArgumentException("Unknown " + typeof(BaseMethodDeclarationSyntax).FullName, "item");
}
示例10: Inspect
private IEnumerable<string> Inspect(BlockSyntax block)
{
var startLine = GetSpan(block.OpenBraceToken).StartLinePosition.Line;
var endLine = GetSpan(block.CloseBraceToken).EndLinePosition.Line;
if (endLine - startLine >= maxLen)
yield return Report(block.OpenBraceToken, "Слишком длинный блок инструкций. Попытайтесь разбить его на вспомогательные методы");
}
示例11: VisitBlock
public override void VisitBlock(BlockSyntax node)
{
foreach (var statement in node.Statements)
{
base.Visit(statement);
}
}
示例12: ParenthesizedLambdaExpression
public ParenthesizedLambdaExpressionSyntax ParenthesizedLambdaExpression(BlockSyntax blocks)
{
return SF.ParenthesizedLambdaExpression(
Block(
ReturnStatement(
InvocationExpression(
Extensions.MemberAccess(
InvocationExpression(
Extensions.MemberAccess(
IdentifierName("Task"),
IdentifierName("Run")
)
).AddArgumentListArguments(
Argument(
SF.ParenthesizedLambdaExpression(
blocks
)
)
),
IdentifierName("AsAsyncOperation")
)
).AddArgumentListArguments()
)
)
);
}
示例13: AddSequencePoint
internal static BoundStatement AddSequencePoint(BlockSyntax blockSyntax, BoundStatement rewrittenStatement, bool isPrimaryCtor)
{
TextSpan span;
if (isPrimaryCtor)
{
// For a primary constructor block: ... [|{|] ... }
return new BoundSequencePointWithSpan(blockSyntax, rewrittenStatement, blockSyntax.OpenBraceToken.Span);
}
var parent = blockSyntax.Parent as ConstructorDeclarationSyntax;
if (parent != null)
{
span = CreateSpanForConstructorDeclaration(parent);
}
else
{
// This inserts a sequence points to any prologue code for method declarations.
var start = blockSyntax.Parent.SpanStart;
var end = blockSyntax.OpenBraceToken.GetPreviousToken().Span.End;
span = TextSpan.FromBounds(start, end);
}
return new BoundSequencePointWithSpan(blockSyntax, rewrittenStatement, span);
}
示例14: AddTrailingBlankLine
public static BlockSyntax AddTrailingBlankLine(BlockSyntax block)
{
Debug.Assert(block != null && NeedsTrailingBlankLine(block));
return block
.WithTrailingTrivia(block.GetTrailingTrivia().Add(SyntaxFactory.CarriageReturnLineFeed))
.WithAdditionalAnnotations(Formatter.Annotation);
}
示例15: Block
private static string Block(BlockSyntax node, bool braces = true)
{
var output = (braces ? "{" + NewLine : "");
output += string.Join("", node.ChildNodes().Select(SyntaxNode));
return output + (braces ? "}" + NewLine + NewLine : "");
}