File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- // Do not remove this, it is needed to retain calls to conditional methods in release builds
2- #define DEBUG
3-
4- using BenchmarkDotNet . Configs ;
1+ using BenchmarkDotNet . Configs ;
52using BenchmarkDotNet . Reports ;
63using BenchmarkDotNet . Running ;
74using BenchmarkDotNetVisualizer . Utilities ;
@@ -152,21 +149,13 @@ private static void PrintMessages()
152149 /// </returns>
153150 public static bool IsRunningInDebugMode ( )
154151 {
155- //NOTE: #if Directives does not work because applies in compile-time not run-time
156- //#if DEBUG
157- //return true;
158- //#else
159- //return false;
160- //#endif
161- RunIfDebug ( ) ;
162- return debugging ;
163- }
164-
165- [ Conditional ( "DEBUG" ) ]
166- private static void RunIfDebug ( )
167- {
168- debugging = true ;
152+ //NOTE: #if DEBUG or [Conditional("DEBUG")] don't work for libraries because these are applied in compile-time not run-time
153+ var customAttributes = Assembly . GetEntryAssembly ( ) ! . GetCustomAttributes ( typeof ( DebuggableAttribute ) , false ) ;
154+ if ( customAttributes ? . Length == 1 )
155+ {
156+ var attribute = ( DebuggableAttribute ) customAttributes [ 0 ] ;
157+ return attribute . IsJITOptimizerDisabled && attribute . IsJITTrackingEnabled ;
158+ }
159+ return false ;
169160 }
170-
171- private static bool debugging ;
172161}
You can’t perform that action at this time.
0 commit comments