예제 #1
0
            private static IDictionary <Type, RuntimeModule> GetAllRuntimeModules(
                ILoader loader,
                object[] seedModules)
            {
                var runtimeModules = new RuntimeModule[seedModules.Length];

                for (var i = 0; i < runtimeModules.Length; ++i)
                {
                    var m = seedModules[i];
                    if (m is Type)
                    {
                        runtimeModules[i] = loader.GetRuntimeModule((Type)m, null);
                    }
                    else
                    {
                        runtimeModules[i] = loader.GetRuntimeModule(m.GetType(), m);
                    }
                }

                var result = new Dictionary <Type, RuntimeModule>();

                for (var i = 0; i < seedModules.Length; ++i)
                {
                    result.Add(runtimeModules[i].Module.GetType(), runtimeModules[i]);
                }

                // Fan out and instantiate all modules included by the seed modules
                var toInclude = new Queue <Type>();

                for (var i = 0; i < runtimeModules.Length; ++i)
                {
                    var includes = runtimeModules[i].Includes;
                    for (var j = 0; j < includes.Length; ++j)
                    {
                        toInclude.Enqueue(includes[j]);
                    }
                }

                while (toInclude.Count > 0)
                {
                    var t = toInclude.Dequeue();
                    if (result.ContainsKey(t))
                    {
                        continue;
                    }

                    var runtimeModule = loader.GetRuntimeModule(t, null);
                    result.Add(t, runtimeModule);

                    for (var i = 0; i < runtimeModule.Includes.Length; ++i)
                    {
                        toInclude.Enqueue(runtimeModule.Includes[i]);
                    }
                }

                return(result);
            }