PageRenderTime 37ms CodeModel.GetById 12ms 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. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. namespace Microsoft.Practices.Composite.Modularity
  21. {
  22. /// <summary>
  23. /// Implements a <see cref="IModuleEnumerator"/> that enumerates through module metadata defined explicitly.
  24. /// </summary>
  25. public class StaticModuleEnumerator : IModuleEnumerator
  26. {
  27. readonly List<ModuleInfo> _modules = new List<ModuleInfo>();
  28. /// <summary>
  29. /// Gets a list of metadata information of the modules.
  30. /// </summary>
  31. /// <returns>An array of <see cref="ModuleInfo"/>.</returns>
  32. public ModuleInfo[] GetModules()
  33. {
  34. return _modules.ToArray();
  35. }
  36. /// <summary>
  37. /// Gets a list of metadata information of the modules that should be loaded at startup.
  38. /// </summary>
  39. /// <returns>An array of <see cref="ModuleInfo"/>.</returns>
  40. public ModuleInfo[] GetStartupLoadedModules()
  41. {
  42. return _modules.ToArray();
  43. }
  44. /// <summary>
  45. /// Gets the metadata information of a module by its name.
  46. /// </summary>
  47. /// <param name="moduleName">The module's name.</param>
  48. /// <returns>A <see cref="ModuleInfo"/> associated with the <paramref name="moduleName"/> parameter.</returns>
  49. public ModuleInfo GetModule(string moduleName)
  50. {
  51. return _modules.FirstOrDefault(moduleInfo => moduleInfo.ModuleName == moduleName);
  52. }
  53. /// <summary>
  54. /// Registers a module with the <see cref="StaticModuleEnumerator" />.
  55. /// </summary>
  56. /// <param name="moduleType">The module type. This class should implement <see cref="IModule"/>.</param>
  57. /// <param name="dependsOn">The names of the modules that this module depends on, if any.</param>
  58. /// <returns>The same instance of <see cref="StaticModuleEnumerator"/>.</returns>
  59. /// <remarks>The module name will be the Name of the type specified in <paramref name="moduleType"/>.</remarks>
  60. public StaticModuleEnumerator AddModule(Type moduleType, params string[] dependsOn)
  61. {
  62. ModuleInfo moduleInfo = new ModuleInfo(moduleType.Assembly.FullName
  63. , moduleType.FullName
  64. , moduleType.Name
  65. , dependsOn);
  66. _modules.Add(moduleInfo);
  67. return this;
  68. }
  69. }
  70. }