c# - .NET assert assertions are enabled -


how 1 assert assertions enabled in c#?

here's link related answer java, not work in c#.

the purpose of prevent use of release-type assemblies because efficiency of no concern might running assertions working, there in places preference debug-type assemblies.

use of debug.assert(false) not satisfactory because creates dialog , requires user interaction. know assertions work without "noise". java solution noiseless.

update: there's simpler solution. other 1 still below curious.

public static bool areassertionsenabled =  #if debug   true  #else   false  #endif  ; 

looks nasty quite simple.


let's first @ causes debug.assert disappear in non-debug builds:

[conditional("debug"), __dynamicallyinvokable] public static void assert(bool condition) {     traceinternal.assert(condition); } 

it's [conditional("debug")]. inspires following solution:

public static bool areassertionsenabled = false;  static myclassname() { maybesetenabled(); /* call deleted in release builds */ }  [conditional("debug")] static void maybesetenabled() {     areassertionsenabled = true; } 

you can refactor areassertionsenabled can readonly. can't think of way right now.

you can check boolean value areassertionsenabled , perform logic based on it.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -