@@ -16,14 +16,15 @@ namespace BenchmarkDotNet.Running
16
16
{
17
17
public static partial class BenchmarkConverter
18
18
{
19
+ private const BindingFlags AllMethodsFlags = BindingFlags . Static | BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ;
20
+
19
21
public static BenchmarkRunInfo TypeToBenchmarks ( Type type , IConfig config = null )
20
22
{
21
23
if ( type . IsGenericTypeDefinition )
22
24
throw new ArgumentException ( $ "{ type . Name } is generic type definition, use BenchmarkSwitcher for it") ; // for "open generic types" should be used BenchmarkSwitcher
23
25
24
26
// We should check all methods including private to notify users about private methods with the [Benchmark] attribute
25
- var bindingFlags = BindingFlags . Static | BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ;
26
- var benchmarkMethods = GetOrderedBenchmarkMethods ( type . GetMethods ( bindingFlags ) ) ;
27
+ var benchmarkMethods = GetOrderedBenchmarkMethods ( type . GetMethods ( AllMethodsFlags ) ) ;
27
28
28
29
return MethodsToBenchmarksWithFullConfig ( type , benchmarkMethods , config ) ;
29
30
}
@@ -42,13 +43,13 @@ private static MethodInfo[] GetOrderedBenchmarkMethods(MethodInfo[] methods)
42
43
43
44
private static BenchmarkRunInfo MethodsToBenchmarksWithFullConfig ( Type type , MethodInfo [ ] benchmarkMethods , IConfig config )
44
45
{
45
- var allPublicMethods = type . GetMethods ( ) ; // benchmarkMethods can be filtered, without Setups, look #564
46
+ var allMethods = type . GetMethods ( AllMethodsFlags ) ; // benchmarkMethods can be filtered, without Setups, look #564
46
47
var configPerType = GetFullTypeConfig ( type , config ) ;
47
48
48
- var globalSetupMethods = GetAttributedMethods < GlobalSetupAttribute > ( allPublicMethods , "GlobalSetup" ) ;
49
- var globalCleanupMethods = GetAttributedMethods < GlobalCleanupAttribute > ( allPublicMethods , "GlobalCleanup" ) ;
50
- var iterationSetupMethods = GetAttributedMethods < IterationSetupAttribute > ( allPublicMethods , "IterationSetup" ) ;
51
- var iterationCleanupMethods = GetAttributedMethods < IterationCleanupAttribute > ( allPublicMethods , "IterationCleanup" ) ;
49
+ var globalSetupMethods = GetAttributedMethods < GlobalSetupAttribute > ( allMethods , "GlobalSetup" ) ;
50
+ var globalCleanupMethods = GetAttributedMethods < GlobalCleanupAttribute > ( allMethods , "GlobalCleanup" ) ;
51
+ var iterationSetupMethods = GetAttributedMethods < IterationSetupAttribute > ( allMethods , "IterationSetup" ) ;
52
+ var iterationCleanupMethods = GetAttributedMethods < IterationCleanupAttribute > ( allMethods , "IterationCleanup" ) ;
52
53
53
54
var targets = GetTargets ( benchmarkMethods , type , globalSetupMethods , globalCleanupMethods , iterationSetupMethods , iterationCleanupMethods ) . ToArray ( ) ;
54
55
@@ -135,8 +136,8 @@ private static Tuple<MethodInfo, TargetedAttribute>[] GetAttributedMethods<T>(Me
135
136
return methods . SelectMany ( m => m . GetCustomAttributes < T > ( )
136
137
. Select ( attr =>
137
138
{
138
- AssertMethodHasCorrectSignature ( methodName , m ) ;
139
139
AssertMethodIsAccessible ( methodName , m ) ;
140
+ AssertMethodHasCorrectSignature ( methodName , m ) ;
140
141
AssertMethodIsNotGeneric ( methodName , m ) ;
141
142
142
143
return new Tuple < MethodInfo , TargetedAttribute > ( m , attr ) ;
0 commit comments