• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Syntax.ForEachStatementSyntax类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ForEachStatementSyntax的典型用法代码示例。如果您正苦于以下问题:C# ForEachStatementSyntax类的具体用法?C# ForEachStatementSyntax怎么用?C# ForEachStatementSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ForEachStatementSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ForEachStatementSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: VisitForEachStatement

        public override SyntaxNode VisitForEachStatement(ForEachStatementSyntax node)
        {
            if (node.Identifier.ToString() == renameFrom.ToString())
                node = node.WithIdentifier(renameTo);

            return base.VisitForEachStatement(node);
        }
开发者ID:x335,项目名称:WootzJs,代码行数:7,代码来源:IdentifierRenamer.cs


示例2: VisitForEachStatement

        public override void VisitForEachStatement(ForEachStatementSyntax foreachStatement)
        {
            var expression = $"foreach ({foreachStatement.Type} {foreachStatement.Identifier} in {foreachStatement.InKeyword})";
            var token = CreateBlock(expression, SDNodeRole.ForEach);
            _tokenList.Add(token);

            VisitChildren(token.Statements, foreachStatement.Statement);
        }
开发者ID:Geaz,项目名称:sharpDox,代码行数:8,代码来源:CSharpMethodVisitor.cs


示例3: AddBraces

        public static ForEachStatementSyntax AddBraces(ForEachStatementSyntax forEachStatement)
        {
            Debug.Assert(forEachStatement != null && NeedsBraces(forEachStatement));

            return forEachStatement
                .WithStatement(SyntaxFactory.Block(forEachStatement.Statement))
                .WithAdditionalAnnotations(Formatter.Annotation);
        }
开发者ID:modulexcite,项目名称:StylishCode,代码行数:8,代码来源:StyleHelpers.cs


示例4: VisitForEachStatement

        public override void VisitForEachStatement(ForEachStatementSyntax node)
        {
            if (!(node.Statement is BlockSyntax))
            {
                CreateAuditVariable(node.Statement);
            }

            base.VisitForEachStatement(node);
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:9,代码来源:AuditVariablesWalker.cs


示例5: ForeachCollectionProducerBlock

        internal ForeachCollectionProducerBlock(ForEachStatementSyntax foreachNode, Block successor)
            : base(successor)
        {
            if (foreachNode == null)
            {
                throw new ArgumentNullException(nameof(foreachNode));
            }

            ForeachNode = foreachNode;
        }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:10,代码来源:ForeachCollectionProducerBlock.cs


示例6: VisitForEachStatement

            public override SyntaxNode VisitForEachStatement(ForEachStatementSyntax node)
            {
                node = (ForEachStatementSyntax)base.VisitForEachStatement(node);

                if (!node.Statement.IsKind(SyntaxKind.Block))
                {
                    this.addedAnnotations = true;
                    node = node.WithStatement(SyntaxFactory.Block(node.Statement));
                }

                return node;
            }
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:12,代码来源:SA1503_IfNeedsBlockStatement.cs


示例7: CalculateNewRoot

        private static SyntaxNode CalculateNewRoot(SyntaxNode root, ForEachStatementSyntax foreachSyntax, SemanticModel semanticModel)
        {
            var collection = foreachSyntax.Expression;
            var typeName = foreachSyntax.Type.ToString();
            var invocationToAdd = GetOfTypeInvocation(typeName, collection);
            var namedTypes = semanticModel.LookupNamespacesAndTypes(foreachSyntax.SpanStart).OfType<INamedTypeSymbol>();
            var isUsingAlreadyThere = namedTypes.Any(nt => nt.ToDisplayString() == ofTypeExtensionClass);

            if (isUsingAlreadyThere)
            {
                return root
                    .ReplaceNode(collection, invocationToAdd)
                    .WithAdditionalAnnotations(Formatter.Annotation);
            }
            else
            {
                var usingDirectiveToAdd = SyntaxFactory.UsingDirective(
                    SyntaxFactory.QualifiedName(
                        SyntaxFactory.IdentifierName("System"),
                        SyntaxFactory.IdentifierName("Linq")));

                var annotation = new SyntaxAnnotation("CollectionToChange");
                var newRoot = root.ReplaceNode(
                    collection,
                    collection.WithAdditionalAnnotations(annotation));

                var node = newRoot.GetAnnotatedNodes(annotation).First();
                var closestNamespaceWithUsing = node.AncestorsAndSelf()
                    .OfType<NamespaceDeclarationSyntax>()
                    .FirstOrDefault(n => n.Usings.Count > 0);

                if (closestNamespaceWithUsing != null)
                {
                    newRoot = newRoot.ReplaceNode(
                        closestNamespaceWithUsing,
                        closestNamespaceWithUsing.AddUsings(usingDirectiveToAdd))
                        .WithAdditionalAnnotations(Formatter.Annotation);
                }
                else
                {
                    var compilationUnit = node.FirstAncestorOrSelf<CompilationUnitSyntax>();
                    newRoot = compilationUnit.AddUsings(usingDirectiveToAdd);
                }

                node = newRoot.GetAnnotatedNodes(annotation).First();
                return newRoot
                    .ReplaceNode(node, invocationToAdd)
                    .WithAdditionalAnnotations(Formatter.Annotation);
            }
        }
开发者ID:Azzhag,项目名称:sonarlint-vs,代码行数:50,代码来源:ForeachLoopExplicitConversionCodeFixProvider.cs


示例8: VisitForEachStatement

        public override void VisitForEachStatement(ForEachStatementSyntax node)
        {
            foreach (var invocation in node.DescendantNodes().OfType<InvocationExpressionSyntax>())
            {
                var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(invocation).Symbol;
                if (symbol != null && symbol.IsTaskCreationMethod())
                {
                    Logs.TempLog2.Info("{0}{1}--------------------------", Document.FilePath, node.Parent.ToLog());
                    break;
                }
                if (symbol != null && symbol.IsThreadStart())
                {
                    Logs.TempLog5.Info("{0}{1}--------------------------", Document.FilePath, node.Parent.ToLog());
                    break;
                }

            }
            base.VisitForEachStatement(node);
        }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:19,代码来源:ComplexPatternDetectionWalker.cs


示例9: TrySearchForIfThenContinueStatement

        private static bool TrySearchForIfThenContinueStatement(ForEachStatementSyntax fe, out IfStatementSyntax ifStatement, out string ifType)
        {
            if (fe.Statement is BlockSyntax)
            {
                var block = ((BlockSyntax)fe.Statement);
                if ((block.Statements.Count > 1 && block.Statements.First() is IfStatementSyntax) ||
                    (block.Statements.Count > 0 && block.Statements.First() is IfStatementSyntax && ((IfStatementSyntax)block.Statements.First()).Else != null)                    )
                {
                    ifStatement = (block.Statements.FirstOrDefault() as IfStatementSyntax);
                    if (ifStatement?.Statement is ContinueStatementSyntax || 
                        ((ifStatement?.Statement as BlockSyntax)?.Statements)?.FirstOrDefault() is ContinueStatementSyntax)
                    {
                        ifType = IfWithContinueToWhere;
                        return true;
                    }
                }
            }

            ifStatement = null;
            ifType = null;
            return false;
        }
开发者ID:nyctef,项目名称:ForeachToLinqAnalyzer,代码行数:22,代码来源:DiagnosticAnalyzer.cs


示例10: ConvertIfToLINQ

        private async Task<Document> ConvertIfToLINQ(Document document, IfStatementSyntax ifStatement, ForEachStatementSyntax foreachStatement, CancellationToken c)
        {
            var generator = SyntaxGenerator.GetGenerator(document);

            var oldVariables = ifStatement.Condition.DescendantNodesAndSelf().OfType<IdentifierNameSyntax>().Where(x => x.Identifier.Text == foreachStatement.Identifier.Text);

            var whereCall = generator.InvocationExpression(
                generator.MemberAccessExpression(foreachStatement.Expression, "Where"),
                generator.Argument(
                    generator.ValueReturningLambdaExpression(
                        new[] { generator.LambdaParameter("x") }, 
                        ifStatement.Condition.ReplaceNodes(oldVariables, (x, y) => generator.IdentifierName("x")))));

            var root = await document.GetSyntaxRootAsync(c);

            var newFeStatement = foreachStatement
                .WithExpression((ExpressionSyntax)whereCall)
                .WithStatement(ifStatement.Statement.WithAdditionalAnnotations(Formatter.Annotation));

            var newRoot = root.ReplaceNode(foreachStatement, newFeStatement);
            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:nyctef,项目名称:ForeachToLinqAnalyzer,代码行数:22,代码来源:CodeFixProvider.cs


示例11: GetActiveSpan

        private static TextSpan GetActiveSpan(ForEachStatementSyntax node, ForEachPart part)
        {
            switch (part)
            {
                case ForEachPart.ForEach:
                    return node.ForEachKeyword.Span;

                case ForEachPart.VariableDeclaration:
                    return TextSpan.FromBounds(node.Type.SpanStart, node.Identifier.Span.End);

                case ForEachPart.In:
                    return node.InKeyword.Span;

                case ForEachPart.Expression:
                    return node.Expression.Span;

                default:
                    throw ExceptionUtilities.UnexpectedValue(part);
            }
        }
开发者ID:GeertVL,项目名称:roslyn,代码行数:20,代码来源:CSharpEditAndContinueAnalyzer.cs


示例12: VisitForEachStatement

        public override SyntaxNode VisitForEachStatement(ForEachStatementSyntax node)
        {
            SyntaxNode rewrittenNode = null;

            if (node.Statement != null)
                rewrittenNode = RewriteWithBlockIfRequired(node, node.Statement);

            return base.VisitForEachStatement((ForEachStatementSyntax)rewrittenNode ?? node);
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:9,代码来源:AuditVariablesRewriter.cs


示例13: GetForEachStatementInfo

 public override ForEachStatementInfo GetForEachStatementInfo(ForEachStatementSyntax node)
 {
     MemberSemanticModel memberModel = GetMemberModel(node);
     return memberModel == null ? default(ForEachStatementInfo) : memberModel.GetForEachStatementInfo(node);
 }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:5,代码来源:SyntaxTreeSemanticModel.cs


示例14: ForEachStatementTranslation

 public ForEachStatementTranslation(ForEachStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
 {
     Expression = syntax.Expression.Get<ExpressionTranslation>(this);
     Statement = syntax.Statement.Get<StatementTranslation>(this);
     Type = syntax.Type.Get<TypeTranslation>(this);
 }
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:6,代码来源:ForEachStatementTranslation.cs


示例15: AddForEachKeywordSequencePoint

 /// <summary>
 /// Add sequence point |here|:
 /// 
 /// |foreach| (Type var in expr) { }
 /// </summary>
 /// <remarks>
 /// Hit once, before looping begins.
 /// </remarks>
 private void AddForEachKeywordSequencePoint(ForEachStatementSyntax forEachSyntax, ref BoundStatement result)
 {
     if (this.GenerateDebugInfo)
     {
         BoundSequencePointWithSpan foreachKeywordSequencePoint = new BoundSequencePointWithSpan(forEachSyntax, null, forEachSyntax.ForEachKeyword.Span);
         result = new BoundStatementList(forEachSyntax, ImmutableArray.Create<BoundStatement>(foreachKeywordSequencePoint, result));
     }
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:16,代码来源:LocalRewriter_ForEachStatement.cs


示例16: GetForEachStatementInfo

 public override ForEachStatementInfo GetForEachStatementInfo(ForEachStatementSyntax node)
 {
     return GetForEachStatementInfo((CommonForEachStatementSyntax)node);
 }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:4,代码来源:MemberSemanticModel.cs


示例17: VisitForEachStatement

        public override SyntaxNode VisitForEachStatement(ForEachStatementSyntax node)
        {
            var info = this._semanticModel.GetTypeInfo(node.Expression);

            if (info.IsEnumerable())
            {
                //Note:Here we use __idx${identifierName} as index
                _output.Write(node.ForEachKeyword, "for (var __idx${0} = 0; __idx${0} < ", node.Identifier.ValueText);
                VisitExpression(node.Expression);
                _output.Write(node.Identifier, ".length; __idx${0}++) ", node.Identifier.ValueText);
                _output.TrivialWriteLine('{');

                _output.IncreaseIndent();
                _output.Write(node.Identifier, "var {0} = ", node.Identifier.ValueText);
                Visit(node.Expression);
                _output.WriteLine(node.Identifier, "[__idx${0}];", node.Identifier.ValueText);

                this.Visit(node.Statement);
                this.AppendCompensateSemicolon(node.Statement);
                _output.DecreaseIndent();
                _output.TrivialWrite('}');
            }
            else
            {
                _output.Write(node.ForEachKeyword, "for (var {0} in ", node.Identifier.ValueText);
                VisitExpression(node.Expression);
                _output.TrivialWriteLine(") {");

                _output.IncreaseIndent();
                this.Visit(node.Statement);
                this.AppendCompensateSemicolon(node.Statement);
                _output.DecreaseIndent();

                _output.TrivialWrite('}');
            }

            return node;
        }
开发者ID:rexzh,项目名称:SharpJs,代码行数:38,代码来源:Rewriter_BasicStructure.cs


示例18: VisitForEachStatement

        public override void VisitForEachStatement(ForEachStatementSyntax node)
        {
            Debug.Assert((object)_containingMemberOrLambda == _enclosing.ContainingMemberOrLambda);
            var patternBinder = new PatternVariableBinder(node.Expression, _enclosing);

            AddToMap(node.Expression, patternBinder);
            Visit(node.Expression, patternBinder);

            var binder = new ForEachLoopBinder(patternBinder, node);
            AddToMap(node, binder);

            VisitPossibleEmbeddedStatement(node.Statement, binder);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:LocalBinderFactory.cs


示例19: VisitForEachStatement

 public override void VisitForEachStatement(ForEachStatementSyntax node)
 {
     VisitCommonForEachStatement(node);
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:4,代码来源:LocalBinderFactory.cs


示例20: HandleForeachStatement

        /// <summary>
        /// Handles the given foreach statement.
        /// </summary>
        /// <param name="stmt">Statement</param>
        /// <param name="successor">Successor</param>
        private void HandleForeachStatement(ForEachStatementSyntax stmt, ControlFlowGraphNode successor)
        {
            this.SyntaxNodes.Add(stmt.Expression);
            this.IsLoopHeadNode = true;

            if (successor != null)
            {
                this.ISuccessors.Add(successor);
                successor.IPredecessors.Add(this);
                this.LoopExitNode = successor;
            }

            var foreachNode = new ControlFlowGraphNode(this.Summary);
            this.ISuccessors.Add(foreachNode);
            foreachNode.IPredecessors.Add(this);

            if (stmt.Statement is BlockSyntax)
            {
                foreachNode.Construct((stmt.Statement as BlockSyntax).Statements, 0, false, this);
            }
            else
            {
                foreachNode.Construct(new SyntaxList<StatementSyntax> { stmt.Statement }, 0, false, this);
            }
        }
开发者ID:jerickmsft,项目名称:PSharp,代码行数:30,代码来源:ControlFlowGraphNode.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Syntax.ForStatementSyntax类代码示例发布时间:2022-05-26
下一篇:
C# Syntax.FieldDeclarationSyntax类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap