| | 1 | | using Fluorite.Extensions; |
| | 2 | | using Fluorite.Strainer.Attributes; |
| | 3 | | using Fluorite.Strainer.Models.Metadata; |
| | 4 | |
|
| | 5 | | namespace Fluorite.Strainer.Services.Metadata.Attributes; |
| | 6 | |
|
| | 7 | | public class PropertyMetadataDictionaryProvider : IPropertyMetadataDictionaryProvider |
| | 8 | | { |
| | 9 | | private readonly IPropertyInfoProvider _propertyInfoProvider; |
| | 10 | | private readonly IStrainerAttributeProvider _strainerAttributeProvider; |
| | 11 | | private readonly IAttributePropertyMetadataBuilder _attributePropertyMetadataBuilder; |
| | 12 | |
|
| 8 | 13 | | public PropertyMetadataDictionaryProvider( |
| 8 | 14 | | IPropertyInfoProvider propertyInfoProvider, |
| 8 | 15 | | IStrainerAttributeProvider strainerAttributeProvider, |
| 8 | 16 | | IAttributePropertyMetadataBuilder attributePropertyMetadataBuilder) |
| | 17 | | { |
| 8 | 18 | | _propertyInfoProvider = Guard.Against.Null(propertyInfoProvider); |
| 8 | 19 | | _strainerAttributeProvider = Guard.Against.Null(strainerAttributeProvider); |
| 8 | 20 | | _attributePropertyMetadataBuilder = Guard.Against.Null(attributePropertyMetadataBuilder); |
| 8 | 21 | | } |
| | 22 | |
|
| | 23 | | public IReadOnlyDictionary<string, IPropertyMetadata> GetMetadata(Type type) |
| | 24 | | { |
| 0 | 25 | | Guard.Against.Null(type); |
| | 26 | |
|
| 0 | 27 | | return _propertyInfoProvider.GetPropertyInfos(type) |
| 0 | 28 | | .Select(propertyInfo => _strainerAttributeProvider.GetPropertyAttribute(propertyInfo)) |
| 0 | 29 | | .Where(attribute => attribute is not null) |
| 0 | 30 | | .Select(attribute => attribute!) |
| 0 | 31 | | .ToDictionary(attribute => attribute.Name, attribute => (IPropertyMetadata)attribute) |
| 0 | 32 | | .ToReadOnly(); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public IReadOnlyDictionary<string, IPropertyMetadata> GetMetadata(Type type, StrainerObjectAttribute strainerObjectA |
| | 36 | | { |
| 0 | 37 | | Guard.Against.Null(type); |
| 0 | 38 | | Guard.Against.Null(strainerObjectAttribute); |
| | 39 | |
|
| 0 | 40 | | return _propertyInfoProvider.GetPropertyInfos(type) |
| 0 | 41 | | .Select(propertyInfo => _attributePropertyMetadataBuilder.BuildDefaultMetadataForProperty(strainerObjectAttr |
| 0 | 42 | | .ToDictionary(metadata => metadata.Name, metadata => metadata) |
| 0 | 43 | | .ToReadOnly(); |
| | 44 | | } |
| | 45 | | } |