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


C# Syntax.ForEachStatementSyntax类代码示例

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


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


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