To cache or not to cache - GetCustomAttributes

Viewed 8345

I currently have a function:

public static Attribute GetAttribute(MemberInfo Member, Type AttributeType)
{
    Object[] Attributes = Member.GetCustomAttributes(AttributeType, true);

    if (Attributes.Length > 0)
        return (Attribute)Attributes[0];
    else
        return null;
}

I am wondering if it would be worthwhile caching all the attributes on a property into a Attribute = _cache[MemberInfo][Type] dictionary,

This would require using GetCustomAttributes without any type parameter then enumerating over the result. Is it worth it?

6 Answers
Related