public static class ConventionHelpers
|
{
|
/// <summary>
|
/// The default convention pack.
|
/// </summary>
|
private const string DefaultConventionPackName = "__defaults__";
|
|
/// <summary>
|
/// The convention closure lookup.
|
/// </summary>
|
private static ConcurrentDictionary<string,Func<Type,bool>> _conventionClosureLookup = new ConcurrentDictionary<string, Func<Type, bool>>();
|
|
/// <summary>
|
/// A ConventionPack extension method that registers the exclusive convention pack.
|
/// </summary>
|
/// <param name="exclusivePack"> The exclusivePack to act on.</param>
|
/// <param name="name"> The name.</param>
|
/// <param name="typeFilter"> A filter specifying the type.</param>
|
public static void RegisterExclusiveConventionPack(this ConventionPack exclusivePack, string name, Func<Type,bool> typeFilter)
|
{
|
_conventionClosureLookup.TryAdd(name, typeFilter);
|
|
ConventionRegistry.Remove(DefaultConventionPackName);
|
ConventionRegistry.Remove(name);
|
|
var allFilterFunctions = _conventionClosureLookup.Values;
|
|
// check for any exclusion function
|
ConventionRegistry.Register(
|
DefaultConventionPackName,
|
DefaultConventionPack.Instance,
|
t =>
|
{
|
return allFilterFunctions.All(s => !s(t));
|
});
|
|
ConventionRegistry.Register(name, exclusivePack, typeFilter);
|
}
|
}
|