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

RefactorCodeTypeReference() private method

This method contains the core logic for changing a type reference to use a new type.
private RefactorCodeTypeReference ( CodeTypeReference codeTypeReference, string oldName, string newName ) : void
codeTypeReference System.CodeDom.CodeTypeReference
oldName string
newName string
return void
        private void RefactorCodeTypeReference(CodeTypeReference codeTypeReference, string oldName, string newName)
        {
            // Is this an array type field? Then check the array type.
            if (codeTypeReference.ArrayElementType != null)
            {
                // Is the array type is as same as the type we modified.
                if (codeTypeReference.ArrayElementType.BaseType == oldName)
                {
                    // Change the array type name.
                    codeTypeReference.ArrayElementType.BaseType = newName;
                }
            }
            else
            {
                // We arrive here if the field type is not an array type.
                // Check if the type is a generic type or not.
                if (codeTypeReference.TypeArguments.Count == 0)
                {
                    // Is the field type as same as the type we modified.
                    if (codeTypeReference.BaseType == oldName)
                    {
                        // Change the field type name.
                        codeTypeReference.BaseType = newName;
                    }
                }
                else
                {
                    // We arrive here if the field type is a genric type.
                    // Check for the code type arguments for generic type fields.
                    foreach (CodeTypeReference gtype in codeTypeReference.TypeArguments)
                    {
                        // Do we have a generic argument of type we modified?
                        if (gtype.BaseType == oldName)
                        {
                            // Set the generic argument type name.s
                            gtype.BaseType = newName;
                        }
                    }
                }
            }
        }