Ejemplo n.º 1
0
        /// <summary>
        /// Determines if we need to preface the root namespace to the type
        /// </summary>
        /// <param name="type">The type in question</param>
        /// <param name="codeGenerator">The current proxy generator</param>
        /// <returns><c>true</c> if if we need to preface the root namespace to the type, <c>false</c> otherwise</returns>
        private static bool NeedToPrefaceRootNamespace(Type type, CodeDomClientCodeGenerator codeGenerator)
        {
            // System assemblies never preface with the root namespace
            if (type.Assembly.IsSystemAssembly())
            {
                return(false);
            }
            bool isVbProjectWithRootNamespace = !codeGenerator.IsCSharp && !string.IsNullOrEmpty(codeGenerator.ClientProxyCodeGenerationOptions.ClientRootNamespace);

            bool typeIsGeneratedOnTheClient = (type.IsEnum && codeGenerator.NeedToGenerateEnumType(type)) ||
                                              codeGenerator.EntityDescriptions.Any(dsd => dsd.EntityTypes.Contains(type));

            bool typeNameStartsWithRootNamespace =
                string.Equals(type.Namespace, _rootNamespace, StringComparison.Ordinal) ||
                (!string.IsNullOrEmpty(type.Namespace) && type.Namespace.StartsWith(_rootNamespace + ".", StringComparison.Ordinal));

            return(isVbProjectWithRootNamespace && typeIsGeneratedOnTheClient && !typeNameStartsWithRootNamespace);
        }