| | 1 | | using Fluorite.Strainer.Attributes; |
| | 2 | | using Fluorite.Strainer.Models.Metadata; |
| | 3 | | using System.Reflection; |
| | 4 | |
|
| | 5 | | namespace Fluorite.Strainer.Services.Metadata.Attributes; |
| | 6 | |
|
| | 7 | | public class AttributePropertyMetadataBuilder : IAttributePropertyMetadataBuilder |
| | 8 | | { |
| | 9 | | private readonly IStrainerOptionsProvider _strainerOptionsProvider; |
| | 10 | |
|
| 9 | 11 | | public AttributePropertyMetadataBuilder(IStrainerOptionsProvider strainerOptionsProvider) |
| | 12 | | { |
| 9 | 13 | | _strainerOptionsProvider = Guard.Against.Null(strainerOptionsProvider); |
| 9 | 14 | | } |
| | 15 | |
|
| | 16 | | public IPropertyMetadata BuildDefaultMetadata(StrainerObjectAttribute attribute, PropertyInfo propertyInfo) |
| | 17 | | { |
| 1 | 18 | | Guard.Against.Null(attribute); |
| 1 | 19 | | Guard.Against.Null(propertyInfo); |
| | 20 | |
|
| 1 | 21 | | return new PropertyMetadata(propertyInfo.Name, propertyInfo) |
| 1 | 22 | | { |
| 1 | 23 | | IsDefaultSorting = true, |
| 1 | 24 | | DefaultSortingWay = attribute.DefaultSortingWay, |
| 1 | 25 | | IsFilterable = attribute.IsFilterable, |
| 1 | 26 | | IsSortable = attribute.IsSortable, |
| 1 | 27 | | }; |
| | 28 | | } |
| | 29 | |
|
| | 30 | | public IPropertyMetadata BuildDefaultMetadataForProperty(StrainerObjectAttribute attribute, PropertyInfo propertyInf |
| | 31 | | { |
| 0 | 32 | | Guard.Against.Null(attribute); |
| 0 | 33 | | Guard.Against.Null(propertyInfo); |
| | 34 | |
|
| 0 | 35 | | var isDefaultSorting = attribute.DefaultSortingPropertyInfo == propertyInfo; |
| 0 | 36 | | var defaultSortingWay = isDefaultSorting |
| 0 | 37 | | ? attribute.DefaultSortingWay |
| 0 | 38 | | : _strainerOptionsProvider.GetStrainerOptions().DefaultSortingWay; |
| | 39 | |
|
| 0 | 40 | | return new PropertyMetadata(propertyInfo.Name, propertyInfo) |
| 0 | 41 | | { |
| 0 | 42 | | IsDefaultSorting = isDefaultSorting, |
| 0 | 43 | | DefaultSortingWay = defaultSortingWay, |
| 0 | 44 | | IsFilterable = attribute.IsFilterable, |
| 0 | 45 | | IsSortable = attribute.IsSortable, |
| 0 | 46 | | }; |
| | 47 | | } |
| | 48 | | } |