static List<MethodInfo> GetMethodsByAttribute(Type type, Type attr)
{
List<MethodInfo> list = new List<MethodInfo>();
Type t = type;
while (t != typeof(object)) {
int count = 0;
foreach (MethodInfo mi in t.GetMethods(DefaultBindingFlags)) {
if (mi.IsDefined(attr, false)) {
list.Add(mi);
count++;
}
}
// FIXME: MS.NET is checking for this with the verifier at assembly load time.
if (count > 1)
throw new TypeLoadException(
String.Format("Type '{0}' has more than one method with the following attribute: '{1}'.", type.AssemblyQualifiedName, attr.FullName));
t = t.BaseType;
}
// optimize memory usage
return list.Count == 0 ? null : list;
}