| | | 1 | | using Plainquire.Filter.Abstractions; |
| | | 2 | | using System; |
| | | 3 | | |
| | | 4 | | namespace Plainquire.Filter; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Factory for creating instances of <see cref="EntityFilter{TEntity}"/>. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class EntityFilterFactory |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Creates an instance of <see cref="EntityFilter{TEntity}"/>. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="entityType">The type of entity to filter</param> |
| | | 15 | | /// <param name="configuration">The configuration to assign to the created filter</param> |
| | | 16 | | public static EntityFilter Create(Type? entityType, FilterConfiguration? configuration) |
| | | 17 | | { |
| | 12 | 18 | | if (entityType == null) |
| | 0 | 19 | | return new EntityFilter(); |
| | | 20 | | |
| | 12 | 21 | | var entityFilterType = typeof(EntityFilter<>).MakeGenericType(entityType); |
| | 12 | 22 | | var entityFilterInstance = Activator.CreateInstance(entityFilterType) |
| | 12 | 23 | | ?? throw new InvalidOperationException($"Unable to create instance of type {entityFilterType.Name}"); |
| | | 24 | | |
| | 12 | 25 | | var entityFilter = (EntityFilter)entityFilterInstance; |
| | 12 | 26 | | entityFilter.Configuration = configuration; |
| | | 27 | | |
| | 12 | 28 | | return entityFilter; |
| | | 29 | | } |
| | | 30 | | } |