private void ReflectGetCustomAttributes(Type classToReflect, Type metadataType) {
AttributeCollection baseAttributes = null;
Hashtable attrHash = new Hashtable();
#if DEBUG
if (CompDescrSwitch.TraceVerbose) {
Debug.WriteLine(" retrieving metadata for " + classToReflect.FullName);
Debug.WriteLine(" classToRefelct: " + classToReflect.FullName);
Debug.WriteLine(" metadataType: " + metadataType.FullName);
}
#endif
// We only want to reflect on one level at a time,
// so if we have a base class above object, we get the
// attributes for that first.
//
Type baseType = classToReflect.BaseType;
if (baseType != typeof(object) && baseType != null) {
baseAttributes = DebugTypeDescriptor.GetAttributes(baseType);
}
if (baseAttributes != null && baseAttributes.Count > 0) {
foreach (Attribute attr in baseAttributes) {
Type attrType = attr.GetType();
if (metadataType.IsAssignableFrom(attrType)) {
attrHash[attr.TypeId] = attr;
}
}
}
// now get our attributes
//
object[] attributes = DebugTypeDescriptor.GetCustomAttributes(classToReflect);
foreach (Attribute attr in attributes) {
Type attrType = attr.GetType();
if (metadataType.IsAssignableFrom(attrType)) {
attrHash[attr.TypeId] = attr;
}
}
// push the values up to the top level
//
foreach (Attribute attr in attrHash.Values) {
AddMember(attr);
}
}