| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="FilterDefinition.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using MyNet.Observable; |
| | | 9 | | |
| | | 10 | | namespace MyNet.UI.ViewModels.List.Filtering.Catalog; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Represents a concrete implementation of <see cref="IFilterDefinition{T}"/> that defines how to create a filter condi |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="key">The unique key identifying the filter.</param> |
| | | 16 | | /// <param name="displayName">The provider for the display name of the filter.</param> |
| | | 17 | | /// <param name="factory">The factory function to create instances of the filter condition view model.</param> |
| | | 18 | | /// <typeparam name="T">The type of items to be filtered.</typeparam> |
| | | 19 | | /// <typeparam name="TFilter">The type of the filter condition view model.</typeparam> |
| | | 20 | | public sealed class FilterDefinition<T, TFilter>(string key, IObservableValue<string> displayName, Func<TFilter> factory |
| | | 21 | | : IFilterDefinition<T> |
| | | 22 | | where TFilter : IFilterConditionViewModel<T> |
| | | 23 | | { |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets the unique key that identifies this filter definition. This key is used to distinguish different filter def |
| | | 26 | | /// </summary> |
| | 0 | 27 | | public string Key { get; } = key; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the provider for the display name of this filter definition. This provider is used to obtain the display na |
| | | 31 | | /// </summary> |
| | 0 | 32 | | public IObservableValue<string> DisplayName { get; } = displayName; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the type of the filter condition view model. This property returns the type of the filter condition view mo |
| | | 36 | | /// </summary> |
| | 0 | 37 | | public Type FilterType => typeof(TFilter); |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Creates an instance of the filter condition view model using the factory function provided. This method allows c |
| | | 41 | | /// </summary> |
| | | 42 | | /// <returns>A new instance of the filter condition view model.</returns> |
| | 0 | 43 | | public IFilterConditionViewModel<T> Create() => factory(); |
| | | 44 | | } |
| | | 45 | | |