AutoEntityUnionGenerator.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace InABox.Core
  5. {
  6. public interface IAutoEntityUnionGenerator : IAutoEntityGenerator
  7. {
  8. Type[] Entities { get; }
  9. IFilter? Filter(Type type);
  10. }
  11. public abstract class AutoEntityUnionGenerator<TInterface> : IAutoEntityUnionGenerator
  12. {
  13. public AutoEntityUnionGenerator()
  14. {
  15. Configure();
  16. }
  17. private Dictionary<Type,IFilter> _entities = new Dictionary<Type, IFilter>();
  18. public Type[] Entities => _entities.Keys.ToArray();
  19. public IFilter? Filter(Type type) => _entities.ContainsKey(type) ? _entities[type] : null;
  20. public void Add<TType>(Filter<TType> filter = null) where TType : TInterface
  21. {
  22. _entities[typeof(TType)] = filter;
  23. }
  24. protected abstract void Configure();
  25. public Type Definition => typeof(TInterface);
  26. public abstract bool Distinct { get; }
  27. }
  28. }