Skip to content

Commit bb1fb8c

Browse files
Update Orm/Xtensive.Orm/Reflection/AttributeHelper.cs
Co-authored-by: Alexey Kulakov <alexey.kulakov@dataobjects.net>
1 parent 71b0583 commit bb1fb8c

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

Orm/Xtensive.Orm/Reflection/AttributeHelper.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)