conditional-compilation

Alternatives to Conditional Compilation in C#

浪子不回头ぞ 提交于 2019-12-03 16:59:02
问题 What is the alternative to having code with conditional compilation in C#? I have a class that has lots of code that is based on # ifdef .. After sometime my code is unreadable. Looking for refactoring techniques to use for better readability and maintenance of code with many #if defs 回答1: One thing is to use the ConditionalAttribute: [Conditional("DEBUG")] public void Foo() { // Stuff } // This call will only be compiled into the code if the DEBUG symbol is defined Foo(); It's still

How to define conditional compilation symbols in separate file (not .csproj or app.config)

蓝咒 提交于 2019-12-03 14:44:46
We need to define a conditional compilation symbol in a class library project. This should not be checked in the source control (it doesn't apply to all developers), so it should be defined in someplace other than the .csproj or the app.config file. How can this be achieved? Simon P Stevens I would define your various build types in the configuration manager (menu Build → Configuration Manager ) and set up each of the required constants on each of the build types. You can then have each member of the team simply select the build type they want to do, and it will automatically use the

How does the Conditional attribute work?

﹥>﹥吖頭↗ 提交于 2019-12-03 14:08:32
I have some helper methods marked with [Conditional("XXX")] . The intent is to make the methods conditionally compile when only the XXX conditional compilation symbol is present. We're using this for debugging and tracing functionality and it works quite well. During my research on how the conditional compilation works, I found several sources stating methods tagged with the Conditional attribute will be placed in the IL but calls to the methods will not be executed. How does code get compiled into IL but not executed? How can I verify the behavior is actually as described? I haven't done much

Conditional compilation in CoffeeScript/UglifyJS

淺唱寂寞╮ 提交于 2019-12-03 09:27:13
问题 Using Coffeescript I need to have a go through a build script anyway to update my .js files, and I have two of them, one for debugging and one for production (one uses Uglify to minimize the files, one does not). So I was thinking that it would be convenient to have some conditional compilation as well, with code that only enters the debug build. What is the easiest way to achieve this, ideally controlled by a simple command line switch that I can give to either coffee or uglify? 回答1: If you

Using conditional rules in a makefile

妖精的绣舞 提交于 2019-12-03 09:11:29
问题 I capture the intent of the Makefile in pseudo code, then indicate the issues I have. I'm looking for a Makefile which is more user friendly in a test environment. The correct usage of the Makefile is one of the below. make CATEGORY=parser TEST=basic. make ALL If a user gives "JUST" the commands as indicated below, it should print a message saying "CATEGORY defined TEST undefined" and vice-versa make CATEGORY=parser make TEST=basic I tried writing the Makefile in following ways, but it errors

What C preprocessor conditional should I use for OS X specific code?

不想你离开。 提交于 2019-12-03 06:50:00
问题 What C preprocessor conditional should I use for OS X specific code? I need to include a specific library if I am compiling for OS X or a different header if I am compiling for Linux. I know there is __APPLE__ but I don't know if that is a current conditional for OS X 10.x. 回答1: This list of operating system macros says the presence of both __APPLE__ and __MACH__ indicate OSX. Also confirmed at line 18 of part of the source for fdisk. 回答2: __APPLE__ will tell you you're compiling on an Apple

Alternatives to Conditional Compilation in C#

陌路散爱 提交于 2019-12-03 05:57:07
What is the alternative to having code with conditional compilation in C#? I have a class that has lots of code that is based on # ifdef .. After sometime my code is unreadable. Looking for refactoring techniques to use for better readability and maintenance of code with many #if defs One thing is to use the ConditionalAttribute : [Conditional("DEBUG")] public void Foo() { // Stuff } // This call will only be compiled into the code if the DEBUG symbol is defined Foo(); It's still conditional compilation, but based on attributes rather than #ifdef , which makes it generally simpler. Another

Conditional compilation in CoffeeScript/UglifyJS

人走茶凉 提交于 2019-12-02 23:40:41
Using Coffeescript I need to have a go through a build script anyway to update my .js files, and I have two of them, one for debugging and one for production (one uses Uglify to minimize the files, one does not). So I was thinking that it would be convenient to have some conditional compilation as well, with code that only enters the debug build. What is the easiest way to achieve this, ideally controlled by a simple command line switch that I can give to either coffee or uglify? If you're writing a build script anyway, you can add a preprocessor step to it. Since CoffeeScript uses # to denote

What C preprocessor conditional should I use for OS X specific code?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 20:27:10
What C preprocessor conditional should I use for OS X specific code? I need to include a specific library if I am compiling for OS X or a different header if I am compiling for Linux. I know there is __APPLE__ but I don't know if that is a current conditional for OS X 10.x. This list of operating system macros says the presence of both __APPLE__ and __MACH__ indicate OSX. Also confirmed at line 18 of part of the source for fdisk . __APPLE__ will tell you you're compiling on an Apple platform. Unless you need to support MacOS versions before OS X, that should be good enough. Alternately, you

C# shortcut for #if … #else … #endif like #define something as string

不羁岁月 提交于 2019-12-02 09:51:55
In C# dotNET for Mono, is there an easier way of doing this? #if __MonoCS__ public static SqliteConnection NewConnection #else public static SQLiteConnection NewConnection #endif In C I would be able to #if and then #define something, #else and define it as something else. I know that the C# preprocessor doesn't allow what I want, but is there a simpler way of coping with the differences between SQLite for Windows and Linux? Thanks, Jim Thanks to those who answered. Files that depend on SQLite now contain statements like this at the beginning: #if __MonoCS__ using Mono.Data.Sqlite; using