當前位置: 首頁>>代碼示例>>C#>>正文


C# BlockSyntax類代碼示例

本文整理匯總了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;
        }
開發者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


注:本文中的BlockSyntax類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。