4 using System.Collections.Generic;
5 using System.Reflection;
6 using SiliconStudio.Core.Diagnostics;
8 namespace SiliconStudio.Core.Reflection
16 private static readonly
Logger Log = GlobalLogger.GetLogger(
"AssemblyRegistry");
17 private static readonly
object Lock =
new object();
18 private static readonly Dictionary<string, HashSet<Assembly>> MapCategoryToAssemblies =
new Dictionary<string, HashSet<Assembly>>();
19 private static readonly Dictionary<Assembly, HashSet<string>> MapAssemblyToCategories =
new Dictionary<Assembly, HashSet<string>>();
47 if (categories == null)
throw new ArgumentNullException(
"categories");
48 var assemblies =
new HashSet<Assembly>();
51 foreach (var category
in categories)
56 HashSet<Assembly> assembliesFound;
57 if (MapCategoryToAssemblies.TryGetValue(category, out assembliesFound))
59 foreach (var assembly
in assembliesFound)
60 assemblies.Add(assembly);
73 public static HashSet<Assembly>
Find(params
string[] categories)
86 if (assembly == null)
throw new ArgumentNullException(
"assembly");
87 var categories =
new HashSet<string>();
90 HashSet<string> categoriesFound;
91 if (MapAssemblyToCategories.TryGetValue(assembly, out categoriesFound))
93 foreach (var category
in categoriesFound)
94 categories.Add(category);
112 if (assembly == null)
throw new ArgumentNullException(
"assembly");
113 if (categories == null)
throw new ArgumentNullException(
"categories");
115 HashSet<string> currentRegisteredCategories = null;
119 HashSet<string> registeredCategoriesPerAssembly;
120 if (!MapAssemblyToCategories.TryGetValue(assembly, out registeredCategoriesPerAssembly))
122 registeredCategoriesPerAssembly =
new HashSet<string>();
123 MapAssemblyToCategories.Add(assembly, registeredCategoriesPerAssembly);
126 foreach (var category
in categories)
128 if (
string.IsNullOrWhiteSpace(category))
130 Log.Error(
"Invalid empty category for assembly [{0}]", assembly);
134 if (registeredCategoriesPerAssembly.Add(category))
136 if (currentRegisteredCategories == null)
138 currentRegisteredCategories =
new HashSet<string>();
140 currentRegisteredCategories.Add(category);
143 HashSet<Assembly> registeredAssembliesPerCategory;
144 if (!MapCategoryToAssemblies.TryGetValue(category, out registeredAssembliesPerCategory))
146 registeredAssembliesPerCategory =
new HashSet<Assembly>();
147 MapCategoryToAssemblies.Add(category, registeredAssembliesPerCategory);
150 registeredAssembliesPerCategory.Add(assembly);
154 if (currentRegisteredCategories != null)
156 OnAssemblyRegistered(assembly, currentRegisteredCategories);
170 public static void Register(Assembly assembly, params
string[] categories)
175 private static void OnAssemblyRegistered(Assembly assembly, HashSet<string> categories)
177 EventHandler<AssemblyRegisteredEventArgs> handler = AssemblyRegistered;
static HashSet< Assembly > Find(params string[] categories)
Finds registered assemblies that are associated with the specified categories.
static void Register(Assembly assembly, params string[] categories)
Registers an assembly with the specified categories.
static HashSet< string > FindCategories(Assembly assembly)
Finds registered categories that are associated with the specified assembly.
static EventHandler< AssemblyRegisteredEventArgs > AssemblyRegistered
Occurs when an assembly is registered.
static HashSet< Assembly > FindAll()
Finds all registered assemblies.
static HashSet< Assembly > Find(IEnumerable< string > categories)
Finds registered assemblies that are associated with the specified categories.
Base implementation for ILogger.
Provides a basic infrastructure to associate an assembly with some categories and to query and regist...
An event occuring when an assembly is registered with AssemblyRegistry.
static void Register(Assembly assembly, IEnumerable< string > categories)
Registers an assembly with the specified categories.
Output message to log right away.