Exemplo n.º 1
0
        private static void SortAsc(CodeTypeDeclarationCollection TypeCollection)
        {
            List <CodeTypeDeclaration> codeTypes = new List <CodeTypeDeclaration>();

            codeTypes.AddRange(TypeCollection.OfType <CodeTypeDeclaration>().ToArray());
            CodeTypeDeclaration generatedType = codeTypes.FirstOrDefault(
                type =>
            {
                if (type.UserData[Constants.GENERATED_TYPE] as string != null)
                {
                    return(true);
                }
                return(false);
            });

            if (generatedType != null)
            {
                codeTypes.Remove(generatedType);
            }

            //Sort Types Ascending By Type Name
            codeTypes.Sort((a, b) => { return(String.Compare(a.Name, b.Name)); });
            TypeCollection.Clear();
            TypeCollection.AddRange(codeTypes.ToArray());
            if (generatedType != null)
            {
                TypeCollection.Add(generatedType);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NamespaceDetector"/> class.
        /// </summary>
        /// <param name="typeDeclarations">The type declarations to investigate.</param>
        public NamespaceDetector(CodeTypeDeclarationCollection typeDeclarations)
        {
            Guard.NotNull(() => typeDeclarations, typeDeclarations);
            this.typeDeclarations = typeDeclarations;

            // storedDeclarations = typeDeclarations.OfType<CodeTypeDeclaration>().ToList();
            this.storedDeclarations = typeDeclarations.OfType <CodeTypeDeclaration>().ToArray();

            IEnumerable <string> distinctNamespaces;

            this.ShortestNamespace = DetermineShortestNamespace(this.storedDeclarations, out distinctNamespaces);
            this.namespaces        = distinctNamespaces.ToArray();
        }