/// <summary>
        /// Registers an individual type name with the underlying codegen infrastructure.
        /// </summary>
        /// <param name="type">The type to register.</param>
        /// <param name="containingNamespace">The containing namespace.</param>
        private void RegisterTypeName(Type type, string containingNamespace)
        {
            if (string.IsNullOrEmpty(type.Namespace))
            {
                this.LogError(string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Namespace_Required, type));
                return;
            }

            // Check if we're in conflict
            if (!CodeGenUtilities.RegisterTypeName(type, containingNamespace))
            {
                // Aggressively check for potential conflicts across other entity types.
                IEnumerable <Type> potentialConflicts =
                    // Entity types with namespace matches
                    EntityDescriptions
                    .SelectMany(d => d.EntityTypes)
                    .Where(entity => entity.Namespace == type.Namespace).Distinct();

                foreach (var potentialConflict in potentialConflicts)
                {
                    // Register potential conflicts so we qualify type names correctly
                    // later during codegen.
                    CodeGenUtilities.RegisterTypeName(potentialConflict, containingNamespace);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Returns a <see cref="Type"/> name that is safe to use.
        /// </summary>
        /// <remarks>
        /// This method is not safe for use with generic types.
        /// </remarks>
        /// <param name="typeFullName">The full name of the <see cref="Type"/>.</param>
        /// <param name="containingNamespace">The containing namespace.</param>
        /// <param name="userType">A <see cref="Boolean"/> indicating whether or not the <paramref name="typeFullName"/> is a user type.</param>
        /// <returns>A string representing the safe type name.</returns>
        private static string GetSafeTypeName(string typeFullName, string containingNamespace, bool userType)
        {
            if (string.IsNullOrEmpty(typeFullName))
            {
                throw new ArgumentNullException("typeFullName");
            }

            string typeName      = typeFullName;
            string typeNamespace = string.Empty;

            int idx = typeFullName.LastIndexOf('.');

            if (idx != -1)
            {
                typeName      = typeFullName.Substring(idx + 1);
                typeNamespace = typeFullName.Substring(0, idx);
            }

            if (_useFullTypeNames)
            {
                bool prependRootNamespace = _isVisualBasic && userType && !string.IsNullOrEmpty(_rootNamespace) &&
                                            !(typeNamespace.Equals(_rootNamespace, StringComparison.Ordinal) || typeNamespace.StartsWith(_rootNamespace + ".", StringComparison.Ordinal));

                if (prependRootNamespace)
                {
                    typeFullName = _rootNamespace + "." + typeFullName;
                }

                return(typeFullName);
            }

            bool useFullName = CodeGenUtilities.RegisterTypeName(typeNamespace, typeName, containingNamespace);

            return(useFullName ? typeFullName : typeName);
        }