public void SetUp() { var attributeTarget = ReflectionObjectMother.GetSomeType(); _key1 = new CustomAttributeDataCacheKey(attributeTarget, inherit: true); _key2 = new CustomAttributeDataCacheKey(ReflectionObjectMother.GetSomeParameter(), true); _key3 = new CustomAttributeDataCacheKey(attributeTarget, false); _key4 = new CustomAttributeDataCacheKey(attributeTarget, true); }
private static IReadOnlyCollection <ICustomAttributeData> GetCachedAttributes <T> ( T target, Func <T, IEnumerable <ICustomAttributeData> > attributeDataRetriever) where T : ICustomAttributeProvider { var key = new CustomAttributeDataCacheKey(target, inherit: false); // Optimization: Do not extract code duplication into method with Func parameters. This would require creating a closure that captures // variables from an outer scope, which is expensive. IReadOnlyCollection <ICustomAttributeData> attributes; if (s_cache.TryGetValue(key, out attributes)) { return(attributes); } return(s_cache.GetOrAdd(key, k => attributeDataRetriever((T)k.AttributeTarget).ToList().AsReadOnly())); }
private static IReadOnlyCollection <ICustomAttributeData> GetCachedAttributes <T> (T member, bool inherit, Func <T, T> baseMemberProvider) where T : MemberInfo { if (member is IMutableMember) { return(GetAttributes(member, inherit, baseMemberProvider)); } var key = new CustomAttributeDataCacheKey(member, inherit); // Optimization: Do not extract code duplication into method with Func parameters. This would require creating a closure that captures // variables from an outer scope, which is expensive. IReadOnlyCollection <ICustomAttributeData> attributes; if (s_cache.TryGetValue(key, out attributes)) { return(attributes); } return(s_cache.GetOrAdd(key, k => GetAttributes((T)k.AttributeTarget, k.Inherit, baseMemberProvider))); }