本文整理汇总了C#中BlockSyntax类的典型用法代码示例。如果您正苦于以下问题:C# BlockSyntax类的具体用法?C# BlockSyntax怎么用?C# BlockSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockSyntax类属于命名空间,在下文中一共展示了BlockSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:28,代码来源:MethodBodySemanticModel.cs
示例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);
}
开发者ID:TubaKayaDev,项目名称:Call-Graph-Builder-DotNet,代码行数:26,代码来源:MethodSimpifier.cs
示例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);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:26,代码来源:MethodDeclarationSyntax.cs
示例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));
}
开发者ID:ermau,项目名称:Instant,代码行数:31,代码来源:IdentifyingVisitor.cs
示例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);
}
}
开发者ID:jeroenheijmans,项目名称:elasticsearch-net,代码行数:28,代码来源:CodeWithDocumentationWalker.cs
示例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();
}
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:34,代码来源:SA1501CodeFixProvider.cs
示例7: generateRunTaskWrapper
private ArgumentSyntax generateRunTaskWrapper(BlockSyntax blocks, params ParameterSyntax[] parameters)
{
return Argument(taskBuilder
.ParenthesizedLambdaExpression(blocks)
.AddParameterListParameters(parameters)
);
}
开发者ID:holtsoftware,项目名称:House,代码行数:7,代码来源:ServerContextTestsGenerator.cs
示例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;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:26,代码来源:CSharpMethodExtractor.PostProcessor.cs
示例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");
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:29,代码来源:AnalysisExtensions.cs
示例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, "Слишком длинный блок инструкций. Попытайтесь разбить его на вспомогательные методы");
}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:7,代码来源:BlockLengthStyleValidator.cs
示例11: VisitBlock
public override void VisitBlock(BlockSyntax node)
{
foreach (var statement in node.Statements)
{
base.Visit(statement);
}
}
开发者ID:benlaan,项目名称:cs2ts,代码行数:7,代码来源:Transpiler.cs
示例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()
)
)
);
}
开发者ID:holtsoftware,项目名称:House,代码行数:26,代码来源:UWPTaskBuilder.cs
示例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);
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:25,代码来源:LocalRewriter_SequencePoints.cs
示例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);
}
开发者ID:modulexcite,项目名称:StylishCode,代码行数:8,代码来源:StyleHelpers.cs
示例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 : "");
}
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:8,代码来源:SyntaxNodeConverter.cs
示例16: VisitBlock
public override void VisitBlock(BlockSyntax node)
{
var statements = node.ChildNodes().OfType<ExpressionStatementSyntax>();
var invocations = statements.Select(s => s.Expression).OfType<InvocationExpressionSyntax>();
var glOperators = invocations.Select(i => i.Expression).OfType<MemberAccessExpressionSyntax>()
.Where(m => m.IsKind(SyntaxKind.SimpleMemberAccessExpression)).Where(s => s.GetFirstToken().Text == nameof(GL));
var beginEnds = glOperators.Select(g => Tuple.Create(g.Parent as InvocationExpressionSyntax, g.ChildNodes().Skip(1).FirstOrDefault()?.GetFirstToken().Text))
.Where(p => p.Item2 == nameof(GL.Begin) || p.Item2 == nameof(GL.End));
// filtering
if (!beginEnds.Any())
{
base.VisitBlock(node);
return;
}
// block contains GL.Begin() or GL.End()
var counter = 0;
Location prevBeginLocation = null;
foreach (var pair in beginEnds)
{
if (pair.Item2 == nameof(GL.Begin))
{
counter++;
if (counter > 1)
{
Diagnostics.Add(Diagnostic.Create(
descriptor: Rule,
location: prevBeginLocation,
messageArgs: nameof(GL) + "." + nameof(GL.End)));
counter = 1;
}
prevBeginLocation = pair.Item1.GetLocation();
}
else if (pair.Item2 == nameof(GL.End))
{
counter--;
if (counter < 0)
{
Diagnostics.Add(Diagnostic.Create(
descriptor: Rule,
location: pair.Item1.GetLocation(),
messageArgs: nameof(GL) + "." + nameof(GL.Begin)));
counter = 0;
}
}
}
if (counter > 0)
{
Diagnostics.Add(Diagnostic.Create(
descriptor: Rule,
location: prevBeginLocation,
messageArgs: nameof(GL) + "." + nameof(GL.End)));
}
base.VisitBlock(node);
}
开发者ID:occar421,项目名称:OpenTKAnalyzer,代码行数:57,代码来源:BeginEndAnalyzer.cs
示例17: AccessorDeclaration
public static AccessorDeclarationSyntax AccessorDeclaration(AccessorDeclarationKind kind = default(AccessorDeclarationKind), BlockSyntax body = null)
{
var result = new AccessorDeclarationSyntax();
result.Kind = kind;
result.Body = body;
return result;
}
开发者ID:modulexcite,项目名称:CSharpSyntax,代码行数:9,代码来源:Syntax.cs
示例18: VisitBlock
public override void VisitBlock(BlockSyntax node)
{
var oldIsInScope = isInScope;
if (!contextParents.Contains(node))
isInScope = false;
base.VisitBlock(node);
if (!isInScope && oldIsInScope)
isInScope = true;
}
开发者ID:x335,项目名称:WootzJs,代码行数:9,代码来源:VariableDeclarationsLocator.cs
示例19: VisitBlock
public override SyntaxNode VisitBlock(BlockSyntax node)
{
if (node.Statements.Count > 2)
{
node = node.WithAdditionalAnnotations(LayoutAnnotations.MultiLineConstructAnnotation);
}
return base.VisitBlock(node);
}
开发者ID:madelson,项目名称:MedallionCodeFormatter,代码行数:9,代码来源:MultiLineConstructAnnotator.cs
示例20: VisitBlock
public override void VisitBlock(BlockSyntax node)
{
foreach (StatementSyntax statement in node.Statements)
{
CreateAuditVariable(statement);
}
base.VisitBlock(node);
}
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:9,代码来源:AuditVariablesWalker.cs
注:本文中的BlockSyntax类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论