The method MetadataUtil.IsAttributeDefined() is indiscriminately calling System.Attribute.IsDefined() and not storing its results in any sort of cache. The patch fixes this by mapping attributeType to member to whether or not it's defined for the given member...
Dictionary<Type, Dictionary<MemberInfo, bool> >
The patch includes most of the file because none of my windows text editors will leave the line endings alone.
Below is what has been changed...
private static Dictionary<Type, Dictionary<MemberInfo, bool> > _attributeChecks = new Dictionary<Type, Dictionary<MemberInfo, bool> >();
public static bool IsAttributeDefined(MemberInfo member, Type attributeType)
{
bool isDefined;
Dictionary<MemberInfo, bool> memberInfoDict;
if (!_attributeChecks.TryGetValue(attributeType, out memberInfoDict))
{
memberInfoDict = new Dictionary<MemberInfo, bool>();
_attributeChecks.Add(attributeType, memberInfoDict);
}
if (!memberInfoDict.TryGetValue(member, out isDefined))
{
isDefined = System.Attribute.IsDefined(member, attributeType);
memberInfoDict.Add(member, isDefined);
}
return isDefined;