/// <summary>
        /// Creates a new code scope for a type is one does not already exist, else it turns the existing scope for the type.
        /// </summary>
        /// <param name="typeName">Name of the type</param>
        /// <param name="definitionAddress">Guerilla definition address for the type</param>
        /// <param name="scopeType">Type of code scope to be created</param>
        /// <returns>The code scope for the type.</returns>
        public MutationCodeScope CreateCodeScopeForType(string typeName, int definitionAddress, MutationCodeScopeType scopeType)
        {
            // Check if there is an entry in the Types list with the same definition address.
            MutationCodeScope codeScope = FindExistingCodeScope(definitionAddress);

            if (codeScope != null)
            {
                // There is an existing code scope for this type so just return that.
                return(codeScope);
            }

            // Create a code safe type name for the new type.
            string            newTypeName, displayName, units, tooltip;
            EditorMarkUpFlags markupFlags;

            MutationCodeFormatter.ProcessFieldName(typeName, out newTypeName, out displayName, out units, out tooltip, out markupFlags);
            if (newTypeName == "" || MutationCodeFormatter.IsValidFieldName(newTypeName) == false)
            {
                // For now we will create a no name type for it, and I will create a preprocessing function later on.
                newTypeName = this.CreateNoNameType();
            }

            // Check if the type is an enum or flags and append the corresponding character.
            if (scopeType == MutationCodeScopeType.Bitmask)
            {
                // Append 'b' for bitmask.
                newTypeName = newTypeName.Insert(0, char.IsUpper(newTypeName[0]) == true ? "b" : "b_");
            }
            else if (scopeType == MutationCodeScopeType.Enum)
            {
                // Append 'e' for enum.
                newTypeName = newTypeName.Insert(0, char.IsUpper(newTypeName[0]) == true ? "e" : "e_");
            }

            // Check if the type name is unique or if it already exists.
            if (this.Types.Keys.Contains(newTypeName) == true)
            {
                string tempTypeName = "";

                // This shouldn't really happen, but if it does loop until we have a valid type name.
                int uniqueInt = 1;
                do
                {
                    // Append an integer to the type name to try and make it unique.
                    tempTypeName = string.Format("{0}{1}", newTypeName, uniqueInt++);
                }while (this.Types.Keys.Contains(tempTypeName) == true);

                // Save the temp type name.
                newTypeName = tempTypeName;
            }

            // Create a new code scope for this type.
            codeScope = new MutationCodeScope(newTypeName, this.Namespace, definitionAddress, scopeType);

            // Add the new type to the types dictionary.
            this.Types.Add(newTypeName, codeScope);

            // Return the new code scope for the type.
            return(codeScope);
        }
        /// <summary>
        /// Creates a new code safe field name that is unique in the current scope and adds it to the fields list for this scope.
        /// </summary>
        /// <param name="fieldType">Type of field.</param>
        /// <param name="fieldName">Name of the field</param>
        /// <param name="displayName">The UI mark up display name for the field.</param>
        /// <param name="units">String to receive the units specifier is one is present</param>
        /// <param name="tooltip">String to receive the tooltip text if it is present</param>
        /// <param name="markupFlags">The UI markup flags for this field.</param>
        /// <returns>The new code safe field name for the field</returns>
        public string CreateCodeSafeFieldName(field_type fieldType, string fieldName, out string displayName, out string units, out string tooltip, out EditorMarkUpFlags markupFlags)
        {
            string newFieldName = "";

            // Satisfy the compiler.
            displayName = string.Empty;
            units       = string.Empty;
            tooltip     = string.Empty;
            markupFlags = EditorMarkUpFlags.None;

            // Check if the field is a padding field.
            if (fieldType == field_type._field_pad || fieldType == field_type._field_skip || fieldType == field_type._field_useless_pad)
            {
                // Create a new padding field name.
                return(AddPaddingField());
            }
            else if (fieldType == field_type._field_explanation)
            {
                // Create a new explanation field name.
                return(AddExplanationField());
            }

            // Check if the name is invalid.
            if (MutationCodeFormatter.IsValidFieldName(fieldName) == false)
            {
                // Create a new no-name field name.
                return(AddNoNameField());
            }

            // Convert the field name to a code safe representation.
            MutationCodeFormatter.ProcessFieldName(fieldName, out newFieldName, out displayName, out units, out tooltip, out markupFlags);
            if (newFieldName == "")
            {
                // Create a new no-name field name.
                return(AddNoNameField());
            }

            // Make sure the new field name is unique in the code scope.
            if (this.Fields.Contains(newFieldName) == true)
            {
                string tempFieldName = "";

                // Loop and append an integer until the field name becomes unique.
                int uniqueInt = 1;
                do
                {
                    // Append an integer to the field name to try and make it unique.
                    tempFieldName = String.Format("{0}{1}", newFieldName, uniqueInt++);
                }while (this.Fields.Contains(tempFieldName) == true);

                // Save the new field name.
                newFieldName = tempFieldName;
            }

            // Add the new field name to the fields list.
            this.Fields.Add(newFieldName);

            // Return the new field name.
            return(newFieldName);
        }