PageRenderTime 12ms CodeModel.GetById 5ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/V1/spikes/AGCompositeApplicationLibrary/AGComposite/Modularity/StaticModuleEnumerator.cs

#
C# | 76 lines | 31 code | 6 blank | 39 comment | 1 complexity | 0b82ef14c0f3c6834936edd7fb5af556 MD5 | raw file
 1//===============================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===============================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===============================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===============================================================================
17
18using System;
19using System.Collections.Generic;
20using System.Linq;
21
22namespace Microsoft.Practices.Composite.Modularity
23{
24    /// <summary>
25    /// Implements a <see cref="IModuleEnumerator"/> that enumerates through module metadata defined explicitly.
26    /// </summary>
27    public class StaticModuleEnumerator : IModuleEnumerator
28    {
29        readonly List<ModuleInfo> _modules = new List<ModuleInfo>();
30
31        /// <summary>
32        /// Gets a list of metadata information of the modules.
33        /// </summary>
34        /// <returns>An array of <see cref="ModuleInfo"/>.</returns>
35        public ModuleInfo[] GetModules()
36        {
37            return _modules.ToArray();
38        }
39
40        /// <summary>
41        /// Gets a list of metadata information of the modules that should be loaded at startup.
42        /// </summary>
43        /// <returns>An array of <see cref="ModuleInfo"/>.</returns>
44        public ModuleInfo[] GetStartupLoadedModules()
45        {
46            return _modules.ToArray();
47        }
48
49        /// <summary>
50        /// Gets the metadata information of a module by its name.
51        /// </summary>
52        /// <param name="moduleName">The module's name.</param>
53        /// <returns>A <see cref="ModuleInfo"/> associated with the <paramref name="moduleName"/> parameter.</returns>
54        public ModuleInfo GetModule(string moduleName)
55        {
56            return _modules.FirstOrDefault(moduleInfo => moduleInfo.ModuleName == moduleName);
57        }
58
59        /// <summary>
60        /// Registers a module with the <see cref="StaticModuleEnumerator" />.
61        /// </summary>
62        /// <param name="moduleType">The module type. This class should implement <see cref="IModule"/>.</param>
63        /// <param name="dependsOn">The names of the modules that this module depends on, if any.</param>
64        /// <returns>The same instance of <see cref="StaticModuleEnumerator"/>.</returns>
65        /// <remarks>The module name will be the Name of the type specified in <paramref name="moduleType"/>.</remarks>
66        public StaticModuleEnumerator AddModule(Type moduleType, params string[] dependsOn)
67        {
68            ModuleInfo moduleInfo = new ModuleInfo(moduleType.Assembly.FullName
69                                                   , moduleType.FullName
70                                                   , moduleType.Name
71                                                   , dependsOn);
72            _modules.Add(moduleInfo);
73            return this;
74        }
75    }
76}