public virtual Attribute this[Type attributeType]
{
get
{
lock (internalSyncObject) {
// 2 passes here for perf. Really! first pass, we just
// check equality, and if we don't find it, then we
// do the IsAssignableFrom dance. Turns out that's
// a relatively expensive call and we try to avoid it
// since we rarely encounter derived attribute types
// and this list is usually short.
//
if (_foundAttributeTypes == null)
{
_foundAttributeTypes = new AttributeEntry[FOUND_TYPES_LIMIT];
}
int ind = 0;
for (; ind < FOUND_TYPES_LIMIT; ind++)
{
if (_foundAttributeTypes[ind].type == attributeType)
{
int index = _foundAttributeTypes[ind].index;
if (index != -1)
{
return _attributes[index];
}
else{
return GetDefaultAttribute(attributeType);
}
}
if (_foundAttributeTypes[ind].type == null)
break;
}
ind = _index++;
if (_index >= FOUND_TYPES_LIMIT)
{
_index = 0;
}
_foundAttributeTypes[ind].type = attributeType;
int count = _attributes.Length;
for (int i = 0; i < count; i++)
{
Attribute attribute = _attributes[i];
Type aType = attribute.GetType();
if (aType == attributeType)
{
_foundAttributeTypes[ind].index = i;
return attribute;
}
}
// now check the hierarchies.
for (int i = 0; i < count; i++)
{
Attribute attribute = _attributes[i];
Type aType = attribute.GetType();
if (attributeType.IsAssignableFrom(aType))
{
_foundAttributeTypes[ind].index = i;
return attribute;
}
}
_foundAttributeTypes[ind].index = -1;
return GetDefaultAttribute(attributeType);
}
}
}