| | 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 class or struct as filterable and/or sortable, setting default |
| | 9 | | /// values for all its properties. |
| | 10 | | /// </summary> |
| | 11 | | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] |
| | 12 | | public class StrainerObjectAttribute : Attribute, IObjectMetadata |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Initializes a new instance of the <see cref="StrainerObjectAttribute"/> |
| | 16 | | /// class. |
| | 17 | | /// </summary> |
| | 18 | | /// <param name="defaultSortingPropertyName"> |
| | 19 | | /// Property name being default sorting property for marked object. |
| | 20 | | /// </param> |
| | 21 | | /// <exception cref="ArgumentNullException"> |
| | 22 | | /// <paramref name="defaultSortingPropertyName"/> is <see langword="null"/>. |
| | 23 | | /// </exception> |
| | 24 | | /// <exception cref="ArgumentException"> |
| | 25 | | /// <paramref name="defaultSortingPropertyName"/> is empty or contains only whitespace characters. |
| | 26 | | /// </exception> |
| 14 | 27 | | public StrainerObjectAttribute(string defaultSortingPropertyName) |
| | 28 | | { |
| 14 | 29 | | DefaultSortingPropertyName = Guard.Against.NullOrWhiteSpace(defaultSortingPropertyName); |
| 14 | 30 | | } |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Initializes a new instance of the <see cref="StrainerObjectAttribute"/> |
| | 34 | | /// class. |
| | 35 | | /// </summary> |
| | 36 | | /// <param name="defaultSortingPropertyName"> |
| | 37 | | /// Property name being default sorting property for marked object. |
| | 38 | | /// </param> |
| | 39 | | /// <param name="defaultSortingWay"> |
| | 40 | | /// A default sorting way for marked object. |
| | 41 | | /// </param> |
| | 42 | | /// <exception cref="ArgumentException"> |
| | 43 | | /// <paramref name="defaultSortingPropertyName"/> is <see langword="null"/>, |
| | 44 | | /// empty or contains only whitespace characters. |
| | 45 | | /// </exception> |
| 0 | 46 | | public StrainerObjectAttribute(string defaultSortingPropertyName, SortingWay defaultSortingWay) : this(defaultSortin |
| | 47 | | { |
| 0 | 48 | | DefaultSortingWay = defaultSortingWay; |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | /// <inheritdoc/> |
| 9 | 52 | | public string DefaultSortingPropertyName { get; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets default sorting way used when applying sorting using default sorting property. |
| | 56 | | /// <para/> |
| | 57 | | /// Defaults to <see langword="null"/>. |
| | 58 | | /// </summary> |
| 2 | 59 | | public SortingWay? DefaultSortingWay { get; } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Gets or sets a value indicating whether marked |
| | 63 | | /// object is marked as filterable. |
| | 64 | | /// <para/> |
| | 65 | | /// Defaults to <see langword="true"/>. |
| | 66 | | /// </summary> |
| 22 | 67 | | public bool IsFilterable { get; set; } = true; |
| | 68 | |
|
| | 69 | | /// <summary> |
| | 70 | | /// Gets or sets a value indicating whether marked |
| | 71 | | /// object is marked as filterable. |
| | 72 | | /// <para/> |
| | 73 | | /// Defaults to <see langword="true"/>. |
| | 74 | | /// </summary> |
| 23 | 75 | | public bool IsSortable { get; set; } = true; |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Gets or sets the <see cref="PropertyInfo"/> for default sorting property. |
| | 79 | | /// </summary> |
| 3 | 80 | | public PropertyInfo? DefaultSortingPropertyInfo { get; set; } |
| | 81 | | } |