Alternatives to Conditional Compilation in C#
问题 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