Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a preprocessor condition with assembly version?

Tags:

c#

.net

Currently in my code I have this if-statement:

if (System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major > 0)
{
     //Stuff that will execute when we get out of beta
}

Since it is possible to predict the outcome of this statement at compile time I wonder, just out of curiosity, if there is a way to replace it with something like

#if MAJOR_VERION > 0
//Do stuff
#endif

Additionally, if this is possible, is it good or bad .net practice?

like image 823
Zeta Two Avatar asked Dec 05 '25 13:12

Zeta Two


1 Answers

You can't do that as such - preprocessor symbols are either "on" or "off" (defined or not), rather than having numeric values.

You could easily define a BETA preprocessor symbol though, in appropriate project configurations. Then you can just remove it when you're out of beta.

(I'm not sure it's generally a good idea to have conditionalized code like that, mind you. If you're not going to execute that code until you're out of beta, how will you beta test that code?)

like image 139
Jon Skeet Avatar answered Dec 12 '25 18:12

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!