Beispiel #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);
        }
 public static bool AssignsVariableUsingKnownInitializer(this TwoFerSolution twoFerSolution) =>
 twoFerSolution.AssignsVariableUsingNullCoalescingOperator() ||
 twoFerSolution.AssignsVariableUsingNullCheck() ||
 twoFerSolution.AssignsVariableUsingIsNullOrEmptyCheck() ||
 twoFerSolution.AssignsVariableUsingIsNullOrWhiteSpaceCheck();