Preconditions
Preconditions copied to clipboard
Enable conditional compilation
I would like to have the ability to turn off the checks in certain conditions or areas of the code. Would you be open to a pull request that adds [Conditional("PRECONDITIONS")]
to the methods, so they could be turned on and off by a define?
It would require all users to define the symbols of course, which isn't ideal.
Can you be more specfic please ?
What is your purpose for doing it ? How a ConditionnalAttribute would help ?
I have some inner loop code, running on mobile devices, that needs to execute as quickly and efficiently as possible. During development, I would like the checks in place to catch logic errors. At runtime, I want to disable them, but only for these inner loop sections of code.
(And yes, I measured, and removing the checks makes a difference in performance and energy usage.)
If you add the ConditionalAttribute, it would then be possible to disable the checks for a specific code file with #undef PRECONDITIONS
at the top of the file. Or actually, more like:
#if RELEASE
#undef PRECONDITIONS
#endif
Right now I have to put that ugly #if … #endif
around all of the checks in those files, which is not ideal.
The downside to adding the attribute, as I mentioned, is that the checks will only be evaluated if you define PRECONDITIONS
somewhere, i.e. in your project file.
Figured it didn't hurt to ask…
I think that's a great feature @starkos