Thinktecture.Tools.Web.Services.CodeGeneration.CodeRefactoringAgent.RefactorCodeStatements C# (CSharp) Method

RefactorCodeStatements() private method

This method updates the references in code statements.
private RefactorCodeStatements ( CodeStatementCollection statements, string oldName, string newName ) : void
statements System.CodeDom.CodeStatementCollection
oldName string
newName string
return void
        private void RefactorCodeStatements(CodeStatementCollection statements, string oldName, string newName)
        {
            // First clear the stackVariables.
            stackVariables.Clear();

            // Do this for all statements.
            foreach (CodeStatement statement in statements)
            {
                // Update the CodeTypeReferences in this statement.
                CodeTypeReferenceCollection ctrs = GetCodeTypeReferenceInCodeStatement(statement);
                RefactorCodeTypeReferenceCollection(ctrs, oldName, newName);
                RefactorMethodNamesInStatement(statement, newName);

                // From this point we can do the additional things we need to do to
                // tweak the statement.

                // Is this a variable declaration statement?
                if (typeof(CodeVariableDeclarationStatement) == statement.GetType())
                {
                    CodeVariableDeclarationStatement vdeclStatement = (CodeVariableDeclarationStatement)statement;
                    stackVariables.Add(vdeclStatement.Name, vdeclStatement);
                    continue;
                }

                // Is this an assignment statement?
                if (typeof(CodeAssignStatement) == statement.GetType())
                {
                    CodeAssignStatement asnStatement = (CodeAssignStatement)statement;
                    // Update the field reference on the left expression.
                    RefactorFieldNamesInFieldReferences(asnStatement.Left, newName);
                    // Update the field reference on the right expression.
                    RefactorFieldNamesInFieldReferences(asnStatement.Right, newName);
                    continue;
                }

                // Is this a return statement?
                if (typeof(CodeMethodReturnStatement) == statement.GetType())
                {
                    CodeMethodReturnStatement retStatement = (CodeMethodReturnStatement)statement;
                    // Update the field reference in the return expression if available.
                    RefactorFieldNamesInFieldReferences(retStatement.Expression, newName);
                }
            }
        }