/Was.OrcSearch/Metadata/AttributeMetadataCollection.cs |
@@ -1,10 +1,6 @@ |
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; |
@@ -13,7 +9,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; |
@@ -28,26 +24,30 @@ |
{ |
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) |
{ |
if (!(property.GetCustomAttribute(typeof(SearchablePropertyAttribute), false) is |
SearchablePropertyAttribute searchablePropertyAttribute)) continue; |
|
var searchableProperty = new SearchableMetadata(property); |
if (!string.IsNullOrWhiteSpace(searchablePropertyAttribute.SearchName)) |
searchableProperty.SearchName = searchablePropertyAttribute.SearchName; |
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; |
|
searchableProperty.Analyze = searchablePropertyAttribute.Analyze; |
searchableProperty.Analyze = searchablePropertyAttribute.Analyze; |
|
searchableProperties.Add(searchableProperty); |
searchableProperties.Add(searchableProperty); |
} |
} |
|
PropertiesCache.Add(_targetType, searchableProperties); |
_propertiesCache.Add(_targetType, searchableProperties); |
return searchableProperties; |
} |
} |