06.HighQualityMethodsHomework/RefactorCSharpPart2Exam/11. CSharp-Part-2-Exam/CSharp-Part-2-Exam/CATaclysm/CATaclysm.cs
/// <summary>
/// Determines the scope of the current variable
/// </summary>
/// <param name="currentToken">Current token</param>
/// <returns>Scope of the variable as string</returns>
Determines the scope of the current variable
Determines the scope of the current variable
private static string CalculateLatestScope(string currentToken)
        {
            var forKeywordIndex = currentToken.IndexOf("for");
            if (forKeywordIndex > -1 && currentToken.IndexOf("foreach") < 0 && CheckValidityOfToken(currentToken, forKeywordIndex - 1, forKeywordIndex + 3))
            {
                return "Loop";
            }
            var whileKeywordIndex = currentToken.IndexOf("while");
            if (whileKeywordIndex > -1 && CheckValidityOfToken(currentToken, whileKeywordIndex - 1, whileKeywordIndex + 5))
            {
                return "Loop";
            }
            var foreachKeywordIndex = currentToken.IndexOf("foreach");
            if (foreachKeywordIndex > -1 && CheckValidityOfToken(currentToken, foreachKeywordIndex - 1, foreachKeywordIndex + 7))
            {
                return "Loop";
            }
            var ifKeywordIndex = currentToken.IndexOf("if");
            if (ifKeywordIndex > -1 && CheckValidityOfToken(currentToken, ifKeywordIndex - 1, ifKeywordIndex + 2))
            {
                return "Conditional Statement";
            }
            var elseKeywordIndex = currentToken.IndexOf("else");
            if (elseKeywordIndex > -1 && CheckValidityOfToken(currentToken, elseKeywordIndex - 1, elseKeywordIndex + 4))
            {
                return "Conditional Statement";
            }
            return null;
        }
private static string CalculateLatestScope ( string currentToken ) { var forKeywordIndex = currentToken . IndexOf ( " " ) ; if ( forKeywordIndex > - 1 && currentToken . IndexOf ( " " ) < 0 && CheckValidityOfToken ( currentToken , forKeywordIndex - 1 , forKeywordIndex + 3 ) ) { return " " ; } var whileKeywordIndex = currentToken . IndexOf ( " " ) ; if ( whileKeywordIndex > - 1 && CheckValidityOfToken ( currentToken , whileKeywordIndex - 1 , whileKeywordIndex + 5 ) ) { return " " ; } var foreachKeywordIndex = currentToken . IndexOf ( " " ) ; if ( foreachKeywordIndex > - 1 && CheckValidityOfToken ( currentToken , foreachKeywordIndex - 1 , foreachKeywordIndex + 7 ) ) { return " " ; } var ifKeywordIndex = currentToken . IndexOf ( " " ) ; if ( ifKeywordIndex > - 1 && CheckValidityOfToken ( currentToken , ifKeywordIndex - 1 , ifKeywordIndex + 2 ) ) { return " " ; } var elseKeywordIndex = currentToken . IndexOf ( " " ) ; if ( elseKeywordIndex > - 1 && CheckValidityOfToken ( currentToken , elseKeywordIndex - 1 , elseKeywordIndex + 4 ) ) { return " " ; } return null ; }
Determines the scope of the current variable
Determines the scope of the current variable
Scope of the variable as string
Scope of the variable as string
currentToken
string
None