Was.OrcSearch – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
4 | office | 2 | using System.Collections; |
1 | office | 3 | using System.Collections.Generic; |
4 | office | 4 | using System.ComponentModel; |
5 | using System.Linq; |
||
1 | office | 6 | using System.Reflection; |
4 | office | 7 | using System.Threading; |
1 | office | 8 | using Was.OrcSearch.Attributes; |
9 | using Was.OrcSearch.Models; |
||
10 | using Was.OrcSearch.Models.Interfaces; |
||
11 | |||
12 | namespace Was.OrcSearch.Metadata |
||
13 | { |
||
14 | public class AttributeMetadataCollection : ReflectionMetadataCollection |
||
15 | { |
||
4 | office | 16 | private static readonly Dictionary<Type, List<SearchableMetadata>> PropertiesCache = |
1 | office | 17 | new Dictionary<Type, List<SearchableMetadata>>(); |
18 | |||
19 | private readonly Type _targetType; |
||
20 | |||
21 | public AttributeMetadataCollection(Type targetType) |
||
22 | : base(targetType) |
||
23 | { |
||
24 | _targetType = targetType; |
||
25 | } |
||
26 | |||
27 | public override IEnumerable<IMetadata> All |
||
28 | { |
||
29 | get |
||
30 | { |
||
4 | office | 31 | if (PropertiesCache.TryGetValue(_targetType, out var storedProperty)) |
1 | office | 32 | return storedProperty; |
33 | |||
34 | var searchableProperties = new List<SearchableMetadata>(); |
||
35 | var properties = _targetType.GetProperties(); |
||
36 | foreach (var property in properties) |
||
37 | { |
||
4 | office | 38 | if (!(property.GetCustomAttribute(typeof(SearchablePropertyAttribute), false) is |
39 | SearchablePropertyAttribute searchablePropertyAttribute)) continue; |
||
40 | |||
41 | var searchableProperty = new SearchableMetadata(property); |
||
42 | if (!string.IsNullOrWhiteSpace(searchablePropertyAttribute.SearchName)) |
||
43 | searchableProperty.SearchName = searchablePropertyAttribute.SearchName; |
||
1 | office | 44 | |
4 | office | 45 | searchableProperty.Analyze = searchablePropertyAttribute.Analyze; |
1 | office | 46 | |
4 | office | 47 | searchableProperties.Add(searchableProperty); |
1 | office | 48 | } |
49 | |||
4 | office | 50 | PropertiesCache.Add(_targetType, searchableProperties); |
1 | office | 51 | return searchableProperties; |
52 | } |
||
53 | } |
||
54 | } |
||
55 | } |