예제 #1
0
            public override void VisitIfElseStatement(IfElseStatement ifElseStatement)
            {
                base.VisitIfElseStatement(ifElseStatement);

                if (ifElseStatement.Parent is IfElseStatement)
                {
                    return;
                }

                var switchExpr = ConvertIfStatementToSwitchStatementAction.GetSwitchExpression(ctx, ifElseStatement.Condition);

                if (switchExpr == null)
                {
                    return;
                }

                var switchSections = new List <SwitchSection> ();

                if (!ConvertIfStatementToSwitchStatementAction.CollectSwitchSections(switchSections, ctx, ifElseStatement, switchExpr))
                {
                    return;
                }
                if (switchSections.Count <= 1)
                {
                    return;
                }

                AddIssue(
                    ifElseStatement.IfToken,
                    ctx.TranslateString("Convert to 'switch' statement"));
            }
예제 #2
0
            public override void VisitIfElseStatement(IfElseStatement ifElseStatement)
            {
                base.VisitIfElseStatement(ifElseStatement);

                if (ifElseStatement.Parent is IfElseStatement)
                {
                    return;
                }

                var switchExpr = ConvertIfStatementToSwitchStatementAction.GetSwitchExpression(ctx, ifElseStatement.Condition);

                if (switchExpr == null)
                {
                    return;
                }
                var switchSections = new List <SwitchSection> ();

                if (!ConvertIfStatementToSwitchStatementAction.CollectSwitchSections(switchSections, ctx, ifElseStatement, switchExpr))
                {
                    return;
                }
                if (switchSections.Count(s => !s.CaseLabels.Any(l => l.Expression.IsNull)) <= 2)
                {
                    return;
                }
                AddIssue(new CodeIssue(
                             ifElseStatement.IfToken,
                             ctx.TranslateString("Convert to 'switch' statement"))
                {
                    IssueMarker = IssueMarker.DottedLine, ActionProvider = { typeof(ConvertIfStatementToSwitchStatementAction) }
                });
            }