/Was.OrcSearch/Metadata/AttributeMetadataCollection.cs |
@@ -1,6 +1,10 @@ |
using System; |
using System.Collections; |
using System.Collections.Generic; |
using System.ComponentModel; |
using System.Linq; |
using System.Reflection; |
using System.Threading; |
using Was.OrcSearch.Attributes; |
using Was.OrcSearch.Models; |
using Was.OrcSearch.Models.Interfaces; |
@@ -9,7 +13,7 @@ |
{ |
public class AttributeMetadataCollection : ReflectionMetadataCollection |
{ |
private static readonly Dictionary<Type, List<SearchableMetadata>> _propertiesCache = |
private static readonly Dictionary<Type, List<SearchableMetadata>> PropertiesCache = |
new Dictionary<Type, List<SearchableMetadata>>(); |
|
private readonly Type _targetType; |
@@ -24,30 +28,26 @@ |
{ |
get |
{ |
if (_propertiesCache.TryGetValue(_targetType, out var storedProperty)) |
if (PropertiesCache.TryGetValue(_targetType, out var storedProperty)) |
return storedProperty; |
|
var searchableProperties = new List<SearchableMetadata>(); |
|
var properties = _targetType.GetProperties(); |
foreach (var property in properties) |
{ |
var searchablePropertyAttribute = |
property.GetCustomAttribute(typeof(SearchablePropertyAttribute), false) as |
SearchablePropertyAttribute; |
if (searchablePropertyAttribute != null) |
{ |
var searchableProperty = new SearchableMetadata(property); |
if (!string.IsNullOrWhiteSpace(searchablePropertyAttribute.SearchName)) |
searchableProperty.SearchName = searchablePropertyAttribute.SearchName; |
if (!(property.GetCustomAttribute(typeof(SearchablePropertyAttribute), false) is |
SearchablePropertyAttribute searchablePropertyAttribute)) continue; |
|
var searchableProperty = new SearchableMetadata(property); |
if (!string.IsNullOrWhiteSpace(searchablePropertyAttribute.SearchName)) |
searchableProperty.SearchName = searchablePropertyAttribute.SearchName; |
|
searchableProperty.Analyze = searchablePropertyAttribute.Analyze; |
searchableProperty.Analyze = searchablePropertyAttribute.Analyze; |
|
searchableProperties.Add(searchableProperty); |
} |
searchableProperties.Add(searchableProperty); |
} |
|
_propertiesCache.Add(_targetType, searchableProperties); |
PropertiesCache.Add(_targetType, searchableProperties); |
return searchableProperties; |
} |
} |