in src/TestFramework/Core/TestToolHelpers.cs [182:221]
public static IList<MethodInfo> GetMethodsByAttribute(
Type attributeType, Type declearedType, bool inherit)
{
IList<MethodInfo> methods = new List<MethodInfo>();
IList<Type> derivedTypes = new List<Type>();
if (inherit)
{
derivedTypes = GetAllDerivedTypes(declearedType);
}
else
{
derivedTypes.Add(declearedType);
}
BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly;
foreach (Type t in derivedTypes)
foreach (MethodInfo mi in t.GetMethods(flags))
{
Attribute attr = Attribute.GetCustomAttribute(mi, attributeType, false);
if (attr != null &&
attr.GetType() == attributeType &&
!methods.Contains(mi))
{
if (mi.GetParameters().Length != 0)
{
throw new InvalidOperationException(
"Test cleanup method cannot contain any parameters.");
}
else if (mi.ReturnType != typeof(void))
{
throw new InvalidOperationException(
"Test cleanup method cannot have return value.");
}
methods.Add(mi);
}
}
return methods;
}