Ejemplo 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);
            }
        }
        /// <summary>
        /// Visits a <see cref="CodeTypeDeclarationCollection"/>.
        /// </summary>
        /// <param name="codeTypeDeclarationCollection">The <see cref="CodeTypeDeclarationCollection"/> to visit.</param>
        protected override void VisitCodeTypeDeclarationCollection(CodeTypeDeclarationCollection codeTypeDeclarationCollection)
        {
            CodeTypeDeclaration[] sortedTypeDeclarations = codeTypeDeclarationCollection.Cast <CodeTypeDeclaration>().OrderBy(c => c.Name).ToArray();
            codeTypeDeclarationCollection.Clear();
            codeTypeDeclarationCollection.AddRange(sortedTypeDeclarations);

            base.VisitCodeTypeDeclarationCollection(codeTypeDeclarationCollection);
        }