当前位置: 首页>>代码示例>>C#>>正文


C# BlockSyntax.WithStatements方法代码示例

本文整理汇总了C#中BlockSyntax.WithStatements方法的典型用法代码示例。如果您正苦于以下问题:C# BlockSyntax.WithStatements方法的具体用法?C# BlockSyntax.WithStatements怎么用?C# BlockSyntax.WithStatements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlockSyntax的用法示例。


在下文中一共展示了BlockSyntax.WithStatements方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitBlock

 public override SyntaxNode VisitBlock(BlockSyntax node)
 {
     if (_isSaveChanges && node.Parent is UsingStatementSyntax && node.Statements.Count > 2)
     {
         _isSaveChanges = false;
         return node.WithStatements(
             SyntaxFactory.List(
                 node.Statements.Take(node.Statements.Count - 2)
                     .Union(new[] { SyntaxFactory.ParseStatement(_edmxName + "SaveChanges(clientContexts);") })
                     .Union(node.Statements.Skip(node.Statements.Count - 2))));
     }
     return base.VisitBlock(node);
 }
开发者ID:bnjMichel,项目名称:waqs,代码行数:13,代码来源:GlobalWCFServiceRewriter.cs

示例2: VisitBlock

 public override SyntaxNode VisitBlock(BlockSyntax node)
 {
     if (_initWAQSModules)
     {
         var statements = new[] { string.Format("            unityContainer.RegisterType<I{0}Service, {0}ServiceClient>(new InjectionConstructor());\r\n", _edmxName), string.Format("            unityContainer.RegisterType<I{0}ClientContext, {0}ClientContext>();\r\n", _edmxName) };
         var value = node.WithStatements(
             SyntaxFactory.List(
                 statements.Select(s => SyntaxFactory.ParseStatement(s)).Union(node.Statements)));
         _initWAQSModules = false;
         return value;
     }
     return base.VisitBlock(node);
 }
开发者ID:bnjMichel,项目名称:waqs,代码行数:13,代码来源:ApplicationStartupRewriter.cs

示例3: VisitBlock

            public override SyntaxNode VisitBlock(BlockSyntax oldBlock)
            {
                if (oldBlock == _oldInnermostBlock)
                {
                    return _newInnermostBlock;
                }

                if (oldBlock == _oldOutermostBlock)
                {
                    var statements = SyntaxFactory.List(oldBlock.Statements.Where(s => s != _declarationStatement).Select(this.Visit));
                    return oldBlock.WithStatements(statements).WithAdditionalAnnotations(Formatter.Annotation);
                }

                return base.VisitBlock(oldBlock);
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:15,代码来源:MoveDeclarationNearReferenceCodeRefactoringProvider.Rewriter.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: WithDeclarationMoved

        private static BlockSyntax WithDeclarationMoved(BlockSyntax scope, LocalDeclarationStatementSyntax declaration, VariableDeclaratorSyntax v, ISemanticModel model, Assumptions assume, CancellationToken cancellationToken)
        {
            Func<SyntaxNode, bool> accesses = s => s.DescendantNodes()
                                                    .OfType<IdentifierNameSyntax>()
                                                    .Where(e => e.Identifier.ValueText == v.Identifier.ValueText)
                                                    .Where(e => model.GetSymbolInfo(e).Symbol == model.GetDeclaredSymbol(v))
                                                    .Any();

            var isOutermostScope = scope.Statements.Contains(declaration);
            var scopeStatements = isOutermostScope
                                ? scope.Statements.SkipWhile(e => e != declaration).Skip(1).ToArray()
                                : scope.Statements.ToArray();

            var statementAccesses = scope.Statements.Where(s => accesses(s)).ToArray();
            if (statementAccesses.Length == 0) return null; //unused local, no change
            var firstAccess = statementAccesses.FirstOrDefault();
            var insertBeforeTarget = firstAccess;
            if (v.Initializer != null && v.Initializer.Value.IsConst(model) != true) {
                insertBeforeTarget = scopeStatements
                                    .TakeWhile(e => e != firstAccess)
                                    .SkipWhile(e => e.HasSideEffects(model, assume) == false)
                                    .Append(firstAccess)
                                    .FirstOrDefault();
            }

            if (statementAccesses.Length == 1 && insertBeforeTarget == firstAccess) {
                if (firstAccess is BlockSyntax) {
                    var reducedScope = WithDeclarationMoved((BlockSyntax)firstAccess, declaration, v, model, assume, cancellationToken);
                    return scope.WithStatements(scope.Statements.Replace(firstAccess, reducedScope));
                }
                if (firstAccess is IfStatementSyntax) {
                    var s = (IfStatementSyntax)firstAccess;
                    if (!accesses(s.Condition)) {
                        if (!accesses(s.Statement) && s.Else.Statement is BlockSyntax) {
                            return scope.WithStatements(
                                scope.Statements.Replace(
                                    s,
                                    s.WithElse(
                                        s.Else.WithStatement(
                                            WithDeclarationMoved(
                                                (BlockSyntax)s.Else.Statement,
                                                declaration,
                                                v,
                                                model,
                                                assume,
                                                cancellationToken)))));
                        } else if (s.Statement is BlockSyntax && (s.Else == null || !accesses(s.Else.Statement))) {
                            return scope.WithStatements(
                                scope.Statements.Replace(
                                    s,
                                    s.WithStatement(
                                        WithDeclarationMoved(
                                            (BlockSyntax)s.Statement,
                                            declaration,
                                            v,
                                            model,
                                            assume,
                                            cancellationToken))));
                        }
                    }
                }
            }
            if (isOutermostScope && scopeStatements.TakeWhile(e => e != insertBeforeTarget).Where(e => !(e is LocalDeclarationStatementSyntax)).None())
                return null; //minimal scope already

            var newDeclaration = declaration.WithDeclaration(declaration.Declaration.WithVariables(v.SepList1()));
            return scope.WithStatements(scope.Statements.InsertBefore(insertBeforeTarget, newDeclaration).List());
        }
开发者ID:Strilanc,项目名称:Croslyn,代码行数:68,代码来源:OverexposedLocal.cs

示例6: LopsidedTerminalBranchesToGuardedBranches

 public static BlockSyntax LopsidedTerminalBranchesToGuardedBranches(BlockSyntax syntax)
 {
     return syntax.WithStatements(syntax.Statements.SelectMany(e => e is IfStatementSyntax ? LopsidedTerminalBranchesToGuardedBranches((IfStatementSyntax)e) : new[] { e }).List());
 }
开发者ID:Strilanc,项目名称:Croslyn,代码行数:4,代码来源:LopsidedTerminalIfsToEarlyReturnGuards.cs

示例7: InlineLargeGuardedBranches2

 private static BlockSyntax InlineLargeGuardedBranches2(BlockSyntax syntax)
 {
     return syntax.WithStatements(syntax.Statements.SelectMany(e => e is IfStatementSyntax ? InlineLargeGuardedBranches2(e as IfStatementSyntax) : new[] { e }).List());
 }
开发者ID:Strilanc,项目名称:Croslyn,代码行数:4,代码来源:InlineLargeGuardedBranches.cs


注:本文中的BlockSyntax.WithStatements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。