@@ -24,27 +24,10 @@ private static class AttributeDictionary<TAttribute> where TAttribute : Attribut
2424 private static readonly Type attributeType = typeof ( TAttribute ) ;
2525 public static readonly ConcurrentDictionary < PerAttributeKey , TAttribute [ ] > Dictionary = new ( ) ;
2626
27- private static List < TAttribute > GetAttributesAsNewList ( MemberInfo member )
28- {
29- var attrObjects = member . GetCustomAttributes ( attributeType , false ) ;
30- var attrs = new List < TAttribute > ( attrObjects . Length ) ;
31- for ( int i = 0 , count = attrObjects . Length ; i < count ; ++ i ) {
32- attrs . Add ( ( TAttribute ) attrObjects [ i ] ) ;
33- }
34- return attrs ;
35- }
27+ public static readonly Func < PerAttributeKey , TAttribute [ ] > AttributesExtractor = ExtractAttributesByKey ;
3628
37- private static void AddAttributesFromBase ( ref List < TAttribute > attributes , MemberInfo member , AttributeSearchOptions options )
29+ private static TAttribute [ ] ExtractAttributesByKey ( PerAttributeKey key )
3830 {
39- if ( member . GetBaseMember ( ) is MemberInfo bm ) {
40- var attrsToAdd = bm . GetAttributes < TAttribute > ( options ) ;
41- if ( attrsToAdd . Count > 0 ) {
42- ( attributes ??= new List < TAttribute > ( attrsToAdd . Count ) ) . AddRange ( attrsToAdd ) ;
43- }
44- }
45- }
46-
47- public static readonly Func < PerAttributeKey , TAttribute [ ] > AttributesExtractor = key => {
4831 var ( member , options ) = key ;
4932
5033 var attributesAsObjects = member . GetCustomAttributes ( attributeType , false ) ;
@@ -74,8 +57,27 @@ private static void AddAttributesFromBase(ref List<TAttribute> attributes, Membe
7457 }
7558
7659 return attributes ? . ToArray ( attributes . Count ) ?? Array . Empty < TAttribute > ( ) ;
77- } ;
78- }
60+ }
61+
62+ private static List < TAttribute > GetAttributesAsNewList ( MemberInfo member )
63+ {
64+ var attrObjects = member . GetCustomAttributes ( attributeType , false ) ;
65+ var attrs = new List < TAttribute > ( attrObjects . Length ) ;
66+ for ( int i = 0 , count = attrObjects . Length ; i < count ; ++ i ) {
67+ attrs . Add ( ( TAttribute ) attrObjects [ i ] ) ;
68+ }
69+ return attrs ;
70+ }
71+
72+ private static void AddAttributesFromBase ( ref List < TAttribute > attributes , MemberInfo member , AttributeSearchOptions options )
73+ {
74+ if ( member . GetBaseMember ( ) is MemberInfo bm ) {
75+ var attrsToAdd = bm . GetAttributes < TAttribute > ( options ) ;
76+ if ( attrsToAdd . Count > 0 ) {
77+ ( attributes ??= new List < TAttribute > ( attrsToAdd . Count ) ) . AddRange ( attrsToAdd ) ;
78+ }
79+ }
80+ }
7981
8082 /// <summary>
8183 /// A shortcut to <see cref="MemberInfo.GetCustomAttributes(Type,bool)"/> method.
0 commit comments