예제 #1
0
        private static SolutionAnalysis AnalyzeVariableAssignment(this TwoFerSolution twoFerSolution)
        {
            if (!twoFerSolution.AssignsVariable())
            {
                return(null);
            }

            if (!twoFerSolution.AssignsVariableUsingKnownInitializer())
            {
                return(twoFerSolution.ReferToMentor());
            }

            if (twoFerSolution.ReturnsStringFormatWithVariable())
            {
                return(twoFerSolution.ApproveWithComment(UseStringInterpolationNotStringFormat));
            }

            if (twoFerSolution.ReturnsStringConcatenationWithVariable())
            {
                return(twoFerSolution.ApproveWithComment(UseStringInterpolationNotStringConcatenation));
            }

            if (!twoFerSolution.ReturnsStringInterpolationWithVariable())
            {
                return(null);
            }

            if (twoFerSolution.AssignsVariableUsingNullCoalescingOperator())
            {
                return(twoFerSolution.ApproveAsOptimal());
            }

            if (twoFerSolution.AssignsVariableUsingNullCheck())
            {
                return(twoFerSolution.ApproveWithComment(UseNullCoalescingOperatorNotTernaryOperatorWithNullCheck));
            }

            if (twoFerSolution.AssignsVariableUsingIsNullOrEmptyCheck())
            {
                return(twoFerSolution.ApproveWithComment(UseNullCoalescingOperatorNotTernaryOperatorWithIsNullOrEmptyCheck));
            }

            if (twoFerSolution.AssignsVariableUsingIsNullOrWhiteSpaceCheck())
            {
                return(twoFerSolution.ApproveWithComment(UseNullCoalescingOperatorNotTernaryOperatorWithIsNullOrWhiteSpaceCheck));
            }

            return(null);
        }
예제 #2
0
        private static SolutionAnalysis AnalyzeSingleLine(this TwoFerSolution twoFerSolution)
        {
            if (!twoFerSolution.UsesSingleLine())
            {
                return(null);
            }

            if (twoFerSolution.ReturnsStringInterpolationWithDefaultValue() ||
                twoFerSolution.ReturnsStringInterpolationWithNullCoalescingOperator())
            {
                return(twoFerSolution.UsesExpressionBody() ?
                       twoFerSolution.ApproveAsOptimal() :
                       twoFerSolution.ApproveWithComment(UseExpressionBodiedMember));
            }

            if (twoFerSolution.ReturnsStringInterpolationWithIsNullOrEmptyCheck())
            {
                return(twoFerSolution.ApproveWithComment(UseNullCoalescingOperatorNotTernaryOperatorWithIsNullOrEmptyCheck));
            }

            if (twoFerSolution.ReturnsStringInterpolationWithIsNullOrWhiteSpaceCheck())
            {
                return(twoFerSolution.ApproveWithComment(UseNullCoalescingOperatorNotTernaryOperatorWithIsNullOrWhiteSpaceCheck));
            }

            if (twoFerSolution.ReturnsStringInterpolationWithNullCheck())
            {
                return(twoFerSolution.ApproveWithComment(UseNullCoalescingOperatorNotTernaryOperatorWithNullCheck));
            }

            if (twoFerSolution.ReturnsStringConcatenation())
            {
                return(twoFerSolution.ApproveWithComment(UseStringInterpolationNotStringConcatenation));
            }

            if (twoFerSolution.ReturnsStringFormat())
            {
                return(twoFerSolution.ApproveWithComment(UseStringInterpolationNotStringFormat));
            }

            return(null);
        }