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


C# Syntax.ForStatementSyntax類代碼示例

本文整理匯總了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ForStatementSyntax的典型用法代碼示例。如果您正苦於以下問題:C# ForStatementSyntax類的具體用法?C# ForStatementSyntax怎麽用?C# ForStatementSyntax使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ForStatementSyntax類屬於Microsoft.CodeAnalysis.CSharp.Syntax命名空間,在下文中一共展示了ForStatementSyntax類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: HasAcceptableIncrementors

 static bool HasAcceptableIncrementors(ForStatementSyntax @for)
 {
     if (@for.Incrementors.Count != 1) return false;
     var unary = @for.Incrementors[0] as PostfixUnaryExpressionSyntax;
     if (unary == null) return false;
     return unary.IsKind(SyntaxKind.PostIncrementExpression) || unary.IsKind(SyntaxKind.PostDecrementExpression);
 }
開發者ID:haroldhues,項目名稱:code-cracker,代碼行數:7,代碼來源:InvertForAnalyzer.cs

示例2: AreDeclarationConditionAndIncrementorUsingTheSameVariable

        static bool AreDeclarationConditionAndIncrementorUsingTheSameVariable(ForStatementSyntax @for)
        {
            SyntaxToken reference;

            if (@for.Declaration != null)
            {
                reference = @for.Declaration.Variables[0].Identifier;
            }
            else
            {
                var initializer = @for.Initializers[0] as AssignmentExpressionSyntax;
                if (initializer == null) return false;
                var name = initializer.Left as IdentifierNameSyntax;
                if (name == null) return false;
                reference = name.Identifier;
            }

            var condition = @for.Condition as BinaryExpressionSyntax;
            var incrementor = @for.Incrementors[0] as PostfixUnaryExpressionSyntax;

            if (!(condition.Left is IdentifierNameSyntax)) return false;
            if (!(incrementor.Operand is IdentifierNameSyntax)) return false;

            var conditionVariableIdentifier = (condition.Left as IdentifierNameSyntax).Identifier;
            var incrementorVariableIdentifier = (incrementor.Operand as IdentifierNameSyntax).Identifier;

            return reference.Text == conditionVariableIdentifier.Text
                && reference.Text == incrementorVariableIdentifier.Text;
        }
開發者ID:haroldhues,項目名稱:code-cracker,代碼行數:29,代碼來源:InvertForAnalyzer.cs

示例3: BindForParts

        private BoundForStatement BindForParts(ForStatementSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
        {
            BoundStatement initializer;
            if (node.Declaration != null)
            {
                Debug.Assert(node.Initializers.Count == 0);
                if (node.Declaration.IsDeconstructionDeclaration)
                {
                    initializer = originalBinder.BindDeconstructionDeclaration(node.Declaration, node.Declaration, diagnostics);
                }
                else
                {
                    ImmutableArray<BoundLocalDeclaration> unused;
                    initializer = originalBinder.BindForOrUsingOrFixedDeclarations(node.Declaration, LocalDeclarationKind.ForInitializerVariable, diagnostics, out unused);
                }
            }
            else
            {
                initializer = originalBinder.BindStatementExpressionList(node.Initializers, diagnostics);
            }

            var condition = (node.Condition != null) ? originalBinder.BindBooleanExpression(node.Condition, diagnostics) : null;
            var increment = originalBinder.BindStatementExpressionList(node.Incrementors, diagnostics);
            var body = originalBinder.BindPossibleEmbeddedStatement(node.Statement, diagnostics);

            Debug.Assert(this.Locals == this.GetDeclaredLocalsForScope(node));
            return new BoundForStatement(node,
                                         this.Locals,
                                         initializer,
                                         condition,
                                         increment,
                                         body,
                                         this.BreakLabel,
                                         this.ContinueLabel);
        }
開發者ID:Rickinio,項目名稱:roslyn,代碼行數:35,代碼來源:ForLoopBinder.cs

示例4: AddBraces

        public static ForStatementSyntax AddBraces(ForStatementSyntax forStatement)
        {
            Debug.Assert(forStatement != null && NeedsBraces(forStatement));

            return forStatement
                .WithStatement(SyntaxFactory.Block(forStatement.Statement))
                .WithAdditionalAnnotations(Formatter.Annotation);
        }
開發者ID:modulexcite,項目名稱:StylishCode,代碼行數:8,代碼來源:StyleHelpers.cs

示例5: VisitForStatement

        public override void VisitForStatement(ForStatementSyntax node)
        {
            if (node.Condition != null)
            {
                _builder.Add(node);
            }

            base.VisitForStatement(node);
        }
開發者ID:XieShuquan,項目名稱:roslyn,代碼行數:9,代碼來源:LocalVariableDeclaratorsCollector.cs

示例6: VisitForStatement

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

            base.VisitForStatement(node);
        }
開發者ID:pzielinski86,項目名稱:RuntimeTestCoverage,代碼行數:9,代碼來源:AuditVariablesWalker.cs

示例7: HasConditionCompatibleWithTheIncrementor

 static bool HasConditionCompatibleWithTheIncrementor(ForStatementSyntax @for)
 {
     var condition = @for.Condition as BinaryExpressionSyntax;
     var postIncrement = IsPostIncrement(@for.Incrementors[0]);
     return condition != null &&
         (
             (postIncrement && condition.OperatorToken.IsKind(SyntaxKind.LessThanToken)) ||
             (!postIncrement && condition.OperatorToken.IsKind(SyntaxKind.GreaterThanEqualsToken))
         );
 }
開發者ID:haroldhues,項目名稱:code-cracker,代碼行數:10,代碼來源:InvertForAnalyzer.cs

示例8: ForInitializerBlock

        internal ForInitializerBlock(ForStatementSyntax forNode, Block successor)
            : base(successor)
        {
            if (forNode == null)
            {
                throw new ArgumentNullException(nameof(forNode));
            }

            ForNode = forNode;
        }
開發者ID:duncanpMS,項目名稱:sonarlint-vs,代碼行數:10,代碼來源:ForInitializerBlock.cs

示例9: ForStatement

        public static string ForStatement(ForStatementSyntax statement)
        {
            var output = "for ";

            output += SyntaxNode(statement.Declaration) + "; " + SyntaxNode(statement.Condition) + "; " + //TODO: these semicolons should be handled in their syntaxParsers
                      SyntaxNode(statement.Incrementors.First()).TrimEnd(); //TODO: handle multiple incrementors

            output += " " + SyntaxNode(statement.Statement);
            return output;
        }
開發者ID:UIKit0,項目名稱:SharpSwift,代碼行數:10,代碼來源:LoopSyntaxParser.cs

示例10: VisitForStatement

            public override void VisitForStatement(ForStatementSyntax node)
            {
                if (node.Declaration != null)
                {
                    AddVariableExpressions(node.Declaration.Variables, _expressions);
                }

                node.Initializers.Do(i => AddExpressionTerms(i, _expressions));
                AddExpressionTerms(node.Condition, _expressions);
                node.Incrementors.Do(i => AddExpressionTerms(i, _expressions));
            }
開發者ID:XieShuquan,項目名稱:roslyn,代碼行數:11,代碼來源:CSharpProximityExpressionsService.RelevantExpressionsCollector.cs

示例11: VisitForStatement

        public override void VisitForStatement(ForStatementSyntax forStatement)
        {
            var initializers = string.Join(" ", forStatement.Initializers.Select(o => o.ToString()));
            var condition = forStatement.Condition?.ToString();
            var interator = string.Join(" ", forStatement.Incrementors.Select(o => o.ToString()));
            var expression = $"for ({initializers}; {condition}; {interator})";

            var token = CreateBlock(expression, SDNodeRole.ForLoop);
            _tokenList.Add(token);

            VisitChildren(token.Statements, forStatement.Statement);
        }
開發者ID:Geaz,項目名稱:sharpDox,代碼行數:12,代碼來源:CSharpMethodVisitor.cs

示例12: VisitForStatement

            public override SyntaxNode VisitForStatement(ForStatementSyntax node)
            {
                node = (ForStatementSyntax)base.VisitForStatement(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

示例13: ForStatementTranslation

        public ForStatementTranslation(ForStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
        {
            //KeyValuePair<int, string>? a = null;            
            //var b = ((bool?)null)?.Equals(false) ?? true ? false ? true : false :true;

            //string str = "\{ ("\{( "(\{ "{}" })" )}") }";

            Condition = syntax.Condition.Get<ExpressionTranslation>(this);
            Declaration = syntax.Declaration.Get<VariableDeclarationTranslation>(this);
            Incrementors = syntax.Incrementors.Get<ExpressionSyntax, ExpressionTranslation>(this);
            Initializers = syntax.Initializers.Get<ExpressionSyntax, ExpressionTranslation>(this);
            Statement = syntax.Statement.Get<StatementTranslation>(this);
        }
開發者ID:asthomas,項目名稱:TypescriptSyntaxPaste,代碼行數:13,代碼來源:ForStatementTranslation.cs

示例14: VisitForStatement

        public override void VisitForStatement(ForStatementSyntax node)
        {
            var tokens = new List<SyntaxToken>();

            if (node.Declaration != null)
            {
                tokens.AddRange(node.Declaration.Variables.Select(v => v.Identifier));
            }

            tracker.AddIdentifiers(tokens);
            Visit(node.Statement);
            tracker.RemoveIdentifiers(tokens);
        }
開發者ID:EkardNT,項目名稱:Roslyn,代碼行數:13,代碼來源:LocalConflictVisitor.cs

示例15: BindForParts

        private BoundForStatement BindForParts(ForStatementSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
        {
            BoundStatement initializer;
            // Declaration and Initializers are mutually exclusive.
            if (_syntax.Declaration != null)
            {
                ImmutableArray<BoundLocalDeclaration> unused;
                initializer = originalBinder.BindForOrUsingOrFixedDeclarations(node.Declaration, LocalDeclarationKind.RegularVariable, diagnostics, out unused);
            }
            else
            {
                initializer = originalBinder.BindStatementExpressionList(node.Initializers, diagnostics);
            }

            BoundExpression condition = null;
            var innerLocals = ImmutableArray<LocalSymbol>.Empty;
            ExpressionSyntax conditionSyntax = node.Condition;
            if (conditionSyntax != null)
            {
                originalBinder = originalBinder.GetBinder(conditionSyntax);
                condition = originalBinder.BindBooleanExpression(conditionSyntax, diagnostics);
                innerLocals = originalBinder.GetDeclaredLocalsForScope(conditionSyntax);
            }

            BoundStatement increment = null;
            SeparatedSyntaxList<ExpressionSyntax> incrementors = node.Incrementors;
            if (incrementors.Count > 0)
            {
                var scopeDesignator = incrementors.First();
                var incrementBinder = originalBinder.GetBinder(scopeDesignator);
                increment = incrementBinder.WrapWithVariablesIfAny(scopeDesignator, incrementBinder.BindStatementExpressionList(incrementors, diagnostics));
            }

            var body = originalBinder.BindPossibleEmbeddedStatement(node.Statement, diagnostics);

            Debug.Assert(this.Locals == this.GetDeclaredLocalsForScope(node));
            return new BoundForStatement(node,
                                         this.Locals,
                                         initializer,
                                         innerLocals,
                                         condition,
                                         increment,
                                         body,
                                         this.BreakLabel,
                                         this.ContinueLabel);
        }
開發者ID:XieShuquan,項目名稱:roslyn,代碼行數:46,代碼來源:ForLoopBinder.cs


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