Alternatives to Conditional Compilation in C#

前端 未结 7 2448
感情败类
感情败类 2021-02-07 21:17

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 unr

相关标签:
7条回答
  • 2021-02-07 21:48

    Polymorphism.

    Approach it the same way as you would any spaghetti code with lots of conditional branches on the same condition.

    Abstract out the differences into a base class or interface.

    Construct the concrete class depending on build (one #if). Pass the concrete object to your App, and then your app calls the methods defined on the interface.

    0 讨论(0)
提交回复
热议问题