| | 1 | | using Fluorite.Strainer.Attributes; |
| | 2 | | using System.Reflection; |
| | 3 | |
|
| | 4 | | namespace Fluorite.Strainer.Services.Metadata.Attributes; |
| | 5 | |
|
| | 6 | | public class AttributeCriteriaChecker : IAttributeCriteriaChecker |
| | 7 | | { |
| | 8 | | public bool CheckIfObjectAttributeIsMatching( |
| | 9 | | StrainerObjectAttribute? attribute, |
| | 10 | | PropertyInfo? propertyInfo, |
| | 11 | | bool isSortableRequired, |
| | 12 | | bool isFilterableRequired) |
| | 13 | | { |
| | 14 | | // An object attribue is matching when all of these conditions are met: |
| | 15 | | // - StrainerObjectAttribute was found |
| | 16 | | // - property info was found |
| | 17 | | // - attribute has sortable flag enabled or sorting is not required |
| | 18 | | // - attribute has filterable flag enabled or filtering is not required |
| 10 | 19 | | return attribute != null |
| 10 | 20 | | && propertyInfo != null |
| 10 | 21 | | && (!isSortableRequired || attribute.IsSortable) |
| 10 | 22 | | && (!isFilterableRequired || attribute.IsFilterable); |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public bool CheckIfPropertyAttributeIsMatching( |
| | 26 | | StrainerPropertyAttribute? attribute, |
| | 27 | | PropertyInfo? propertyInfo, |
| | 28 | | bool isSortableRequired, |
| | 29 | | bool isFilterableRequired, |
| | 30 | | string name) |
| | 31 | | { |
| | 32 | | // An property attribue is matching when all of these conditions are met: |
| | 33 | | // - StrainerPropertyAttribute was found |
| | 34 | | // - property info was found |
| | 35 | | // - attribute has sortable flag enabled or sorting is not required |
| | 36 | | // - attribute has filterable flag enabled or filtering is not required |
| | 37 | | // - attribute/property name equals provided name |
| 16 | 38 | | return attribute is not null |
| 16 | 39 | | && propertyInfo != null |
| 16 | 40 | | && (!isSortableRequired || attribute.IsSortable) |
| 16 | 41 | | && (!isFilterableRequired || attribute.IsFilterable) |
| 16 | 42 | | && string.Equals(attribute.DisplayName ?? attribute.Name, name); |
| | 43 | | } |
| | 44 | | } |