| | 1 | | using Fluorite.Strainer.Models.Metadata; |
| | 2 | | using Fluorite.Strainer.Models.Sorting; |
| | 3 | | using System.Reflection; |
| | 4 | |
|
| | 5 | | namespace Fluorite.Strainer.Attributes; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// Marks a property as filterable and/or sortable. |
| | 9 | | /// </summary> |
| | 10 | | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] |
| | 11 | | public class StrainerPropertyAttribute : Attribute, IPropertyMetadata |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Initializes a new instance of the <see cref="StrainerPropertyAttribute"/> |
| | 15 | | /// class. |
| | 16 | | /// </summary> |
| 20 | 17 | | public StrainerPropertyAttribute() |
| | 18 | | { |
| 20 | 19 | | } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Gets or sets the display name for related property. |
| | 23 | | /// </summary> |
| 26 | 24 | | public string? DisplayName { get; set; } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Gets or sets a value indicating whether related |
| | 28 | | /// property should be used as a default (fallback) property when |
| | 29 | | /// no sorting information was provided but sorting was still requested. |
| | 30 | | /// <para/> |
| | 31 | | /// Default sorting is not perfomed when sorting information was not |
| | 32 | | /// properly recognized. |
| | 33 | | /// <para/> |
| | 34 | | /// Defaults to <see langword="false"/>. |
| | 35 | | /// </summary> |
| 4 | 36 | | public bool IsDefaultSorting { get; set; } = false; |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Gets or sets default sorting way used when related property is marked |
| | 40 | | /// as a default sorting property. |
| | 41 | | /// <para/> |
| | 42 | | /// Defaults to <see langword="null"/>. |
| | 43 | | /// </summary> |
| 0 | 44 | | public SortingWay? DefaultSortingWay { get; set; } = null; |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Gets or sets a value indicating whether related |
| | 48 | | /// property is marked as filterable. |
| | 49 | | /// <para/> |
| | 50 | | /// Defaults to <see langword="true"/>. |
| | 51 | | /// </summary> |
| 26 | 52 | | public bool IsFilterable { get; set; } = true; |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets or sets a value indicating whether related |
| | 56 | | /// property is marked as sortable. |
| | 57 | | /// <para/> |
| | 58 | | /// Defaults to <see langword="true"/>. |
| | 59 | | /// </summary> |
| 30 | 60 | | public bool IsSortable { get; set; } = true; |
| | 61 | |
|
| | 62 | | /// <inheritdoc/> |
| 3 | 63 | | public string Name => PropertyInfo!.Name; |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// Gets or sets the <see cref="System.Reflection.PropertyInfo"/> for |
| | 67 | | /// related property. |
| | 68 | | /// </summary> |
| 14 | 69 | | public PropertyInfo? PropertyInfo { get; set; } |
| | 70 | | } |