/// <summary>
        /// Initalizes the manager with the specified namespaces in the specified assembly
        /// </summary>
        /// <param name="assembly">Assembly in which is searched</param>
        /// <param name="namespaces">Namespace to be registered in the manager</param>
        public void Initialize(Assembly assembly, params string[] namespaces)
        {
            if (Namespaces == null)
            {
                Namespaces = new List <string>();
            }

            Namespaces.AddRange(namespaces);

            var commands = assembly.GetTypes().Where(
                t => t.GetCustomAttribute <CommandAttribute>() != null && Namespaces.Contains(t.Namespace)).ToList();

            foreach (var command in commands)
            {
                command.GetMethod(
                    "Register",
                    BindingFlags.Static |
                    BindingFlags.Public |
                    BindingFlags.FlattenHierarchy)
                .Invoke(null, new[] { command });
                commandHandler[(string)command.GetCustomAttribute <CommandAttribute>().Tag] += (e)
                                                                                               => InitializeCommand(command, e);
            }

            InitializeOneTimeCommand(Namespaces.ToArray(), assembly.GetTypes());
            IsInitialized = true;
        }
        private static Namespaces GetNamespaces(NamespaceMetrics metrics)
        {
            Namespaces @namespace = new Namespaces();

            @namespace.AddRange(MetricsReportBuilder.GetNamespaceResults(metrics));
            return(@namespace);
        }
        public void LoadFromOtherModel(CodeGenerationModel otherModel)
        {
            if (otherModel == null)
            {
                throw new ArgumentNullException(nameof(otherModel));
            }

            Reset();
            Namespaces.AddRange(otherModel.Namespaces);
        }
Esempio n. 4
0
        /// <summary>
        /// Runs this instance.
        /// </summary>
        public void Run(Config config)
        {
            if (AssemblyManager == null)
            {
                throw new InvalidOperationException("AssemblyManager must be set");
            }

            if (ModelBuilder == null)
            {
                throw new InvalidOperationException("ModelBuilder must be set");
            }

            // Setup the PageId function
            ModelBuilder.PageIdFunction = PageIdFunction;

            var assemblySources = AssemblyManager.Load(config);

            // Add exclude list to ModelBuilder
            ModelBuilder.ExcludeList.Clear();
            foreach (var excludeItem in config.ExcludeList)
            {
                if (!string.IsNullOrWhiteSpace(excludeItem))
                {
                    ModelBuilder.ExcludeList.Add(excludeItem);
                }
            }

            // Process all assemblies
            foreach (var assemblySource in assemblySources)
            {
                ModelBuilder.LoadFrom(assemblySource, Registry);
            }

            Namespaces.AddRange(Registry.Namespaces);

            Namespaces.Sort((from, to) => string.CompareOrdinal(@from.Name, to.Name));

            foreach (var @namespace in Namespaces)
            {
                ProcessDescendants(@namespace.Types);
            }

            foreach (var @namespace in Namespaces)
            {
                @namespace.Types.Sort((from, to) => string.CompareOrdinal(@from.Name, to.Name));

                FlattenHierarchy(@namespace.Types);
            }

            // Link extension method to the corresponding classes
            ModelBuilder.ProcessExtensionMethods();

            // inherit documentation
            ModelBuilder.ProcessInheritedDoc();
        }
Esempio n. 5
0
 public XCodeCompileUnit(CodeCompileUnit source) : base()
 {
     if (source != null)
     {
         Namespaces.AddRange(source.Namespaces);
         EndDirectives.AddRange(source.EndDirectives);
         StartDirectives.AddRange(source.StartDirectives);
         AssemblyCustomAttributes.AddRange(source.AssemblyCustomAttributes);
         foreach (string name in source.ReferencedAssemblies)
         {
             ReferencedAssemblies.Add(name);
         }
         foreach (DictionaryEntry item in source.UserData)
         {
             UserData.Add(item.Key, item.Value);
         }
     }
 }
Esempio n. 6
0
        public override void InitialiseFromCode(string code, int startline)
        {
            if (code == null)
            {
                return;
            }
            //Add Everything to existing Properties
            List <TextAsNamespace> tempSpace   = Helper.GetObjects <TextAsNamespace>(code, RegexString.namespaces, 0);
            List <TextAsClass>     tempClass   = new List <TextAsClass>();
            List <TextAsMethod>    tempMethods = new List <TextAsMethod>();

            tempSpace.ForEach(space => tempClass      = Helper.GetObjects <TextAsClass>(space.Code, RegexString.classWithModifiers, 0));
            tempClass.ForEach(tmpclass => tempMethods = Helper.GetObjects <TextAsMethod>(tmpclass.Code, RegexString.methods, tmpclass.StartLine));
            //...and so on for variables , enums and propperties
            Namespaces.AddRange(tempSpace);
            Classes.AddRange(tempClass);
            Methods.AddRange(tempMethods);
            //...
        }
Esempio n. 7
0
        public void MergeWith(IOutputWriter cache)
        {
            // Remove all crawled items
            cache
            .Projects.ForEach(x => {
                Projects.RemoveAll(y => y.File == x.File);
                Files.RemoveAll(y => y.Project != null && y.Project.File == x.File);
            });
            cache
            .Files.ForEach(x => {
                Files.RemoveAll(y => y.File == x.File);
                Usings.RemoveAll(y => y.File.File == x.File);
                UsingAliases.RemoveAll(y => y.File.File == x.File);
                Namespaces.RemoveAll(y => y.File.File == x.File);
                Classes.RemoveAll(y => y.File.File == x.File);
                Interfaces.RemoveAll(y => y.File.File == x.File);
                Structs.RemoveAll(y => y.File.File == x.File);
                Enums.RemoveAll(y => y.File.File == x.File);
                Fields.RemoveAll(y => y.File.File == x.File);
                Methods.RemoveAll(y => y.File.File == x.File);
                Parameters.RemoveAll(y => y.File.File == x.File);
                Variables.RemoveAll(y => y.File.File == x.File);
            });

            // Write new items
            Projects.AddRange(cache.Projects);
            Files.AddRange(cache.Files);
            Usings.AddRange(cache.Usings);
            UsingAliases.AddRange(cache.UsingAliases);
            Namespaces.AddRange(cache.Namespaces);
            Classes.AddRange(cache.Classes);
            Interfaces.AddRange(cache.Interfaces);
            Structs.AddRange(cache.Structs);
            Enums.AddRange(cache.Enums);
            Fields.AddRange(cache.Fields);
            Methods.AddRange(cache.Methods);
            Parameters.AddRange(cache.Parameters);
            Variables.AddRange(cache.Variables);

            BuildTypeIndex();
        }
Esempio n. 8
0
        /// <summary>
        /// Runs this instance.
        /// </summary>
        public void Run(Config config)
        {
            if (AssemblyManager == null)
            {
                throw new InvalidOperationException("AssemblyManager must be set");
            }

            if (ModelBuilder == null)
            {
                throw new InvalidOperationException("ModelBuilder must be set");
            }

            // Setup the PageId function
            ModelBuilder.PageIdFunction = PageIdFunction;

            var assemblySources = AssemblyManager.Load(config);

            // Process all assemblies
            foreach (var assemblySource in assemblySources)
            {
                ModelBuilder.LoadFrom(assemblySource, Registry);
            }

            Namespaces.AddRange(Registry.Namespaces);

            Namespaces.Sort((from, to) => string.CompareOrdinal(@from.Name, to.Name));

            foreach (var @namespace in Namespaces)
            {
                ProcessDescendants(@namespace.Types);
            }

            foreach (var @namespace in Namespaces)
            {
                @namespace.Types.Sort((from, to) => string.CompareOrdinal(@from.Name, to.Name));

                FlattenHierarchy(@namespace.Types);
            }
        }
Esempio n. 9
0
 public static void UsingAllNamespaces()
 {
     Namespaces.AddRange(typeof(Evaluator).Assembly.GetTypes().Select(t => t.Namespace).Where(ns => !string.IsNullOrEmpty(ns)).Distinct());
 }
Esempio n. 10
0
 public void Add(UnitorModel model)
 {
     Types.AddRange(model.Types);
     Namespaces.Clear();
     Namespaces.AddRange(Types.Select(t => t.Namespace).Distinct());
 }