private void RegisterConventions(string name, IConventionPack conventionPack, Func <Type, bool> filter) { if (_registeredConventionPacks .TryGetValue(name, out IConventionPack registeredConventionPack)) { IEnumerable <string> registeredNames = registeredConventionPack .Conventions.Select(rcp => rcp.Name); IEnumerable <string> newNames = conventionPack .Conventions.Select(cp => cp.Name); if (registeredNames.Except(newNames).Any() || newNames.Except(registeredNames).Any()) { throw new Exception($"The convention pack with name '{name}' " + $"is already registered with different convention packages " + $"({string.Join(",", registeredNames)}). " + $"These convention packages differ from the new ones " + $"({string.Join(", ", newNames)})"); } return; } _registeredConventionPacks.Add(name, conventionPack); ConventionRegistry.Register(name, conventionPack, filter); }
/// <summary> /// Registers the conventions. /// </summary> /// <param name="name">The name.</param> /// <param name="conventions">The conventions.</param> /// <param name="filter">The filter.</param> public static void Register(string name, IConventionPack conventions, Func <Type, bool> filter) { if (name == null) { throw new ArgumentNullException("name"); } if (conventions == null) { throw new ArgumentNullException("conventions"); } if (filter == null) { throw new ArgumentNullException("filter"); } lock (__lock) { var container = new ConventionPackContainer { Filter = filter, Name = name, Pack = conventions }; __conventionPacks.Add(container); } }
/// <inheritdoc /> public ISettingsBuilderDatabase AddConvention(IConventionPack conventions, Expression <Func <Type, bool> > filter) { Guard.AgainstNullArgument(conventions, nameof(conventions)); Guard.AgainstNullArgument(filter, nameof(filter)); this.Config.SetConventions(conventions, filter); return(this); }
public IMongoDatabaseBuilder RegisterConventionPack( string name, IConventionPack conventionPack, Func <Type, bool> filter) { _registrationConventionActions.Add( () => RegisterConventions(name, conventionPack, filter)); return(this); }
// constructors /// <summary> /// Initializes a new instance of the <see cref="ConventionRunner" /> class. /// </summary> /// <param name="conventions">The conventions.</param> public ConventionRunner(IConventionPack conventions) { if (conventions == null) { throw new ArgumentNullException("conventions"); } _conventions = conventions.Conventions.ToList(); }
// constructors /// <summary> /// Initializes a new instance of the <see cref="ConventionRunner" /> class. /// </summary> /// <param name="conventions">The conventions.</param> public ConventionRunner(IConventionPack conventions) { if (conventions == null) { throw new ArgumentNullException("conventions"); } _conventions = conventions.Conventions.ToList(); }
/// <summary> /// Appends the conventions in another pack to the end of this pack. /// </summary> /// <param name="other">The other pack.</param> public void Append(IConventionPack other) { if (other == null) { throw new ArgumentNullException("other"); } AddRange(other.Conventions); }
internal static void SetConventions(this HarnessConfiguration config, IConventionPack pack, Expression <Func <Type, bool> > filter) { Guard.AgainstNullArgument(config, nameof(config)); Guard.AgainstNullArgument(pack, nameof(pack)); Guard.AgainstNullArgument(filter, nameof(filter)); var convention = new ConventionConfig { Name = "conventions", ConventionPack = pack, Filter = filter }; config.Conventions = convention; }
/// <summary> /// Registers the conventions. /// </summary> /// <param name="name">The name.</param> /// <param name="conventions">The conventions.</param> /// <param name="filter">The filter.</param> public static void Register(string name, IConventionPack conventions, Func<Type, bool> filter) { if (name == null) { throw new ArgumentNullException("name"); } if (conventions == null) { throw new ArgumentNullException("conventions"); } if (filter == null) { throw new ArgumentNullException("filter"); } lock (__lock) { var container = new ConventionPackContainer { Filter = filter, Name = name, Pack = conventions }; __conventionPacks.Add(container); } }
public IMongoBuilder AddConvention(string name, IConventionPack convention, Func <Type, bool> filter = null) { ConventionRegistry.Register(name, convention, filter ?? ApplyToAll); return(this); }