Recommendation 156: Use features to provide multiple versions of an application
You need to provide multiple versions of your application for the following reasons:
- The app has the experience version and the full feature edition.
- Applications need to mask some of the immature features during an iterative process.
Let's say we have two types of features in our application: The first category is a standalone version, and the full version of the second class provides online functionality. Then, on the feature, you need to customize the two properties "ONLINE" and "OFFLINE". In the experience version, we only open the "OFFLINE" feature. To achieve this, you should not provide two sets of applications, but should pass the minimum settings. Output two release versions for one application. All this, can be passed. NET (Attribute) to implement.
classMyService {[Conditional ("ONLINE")] Public voidtesting () {Console.WriteLine ("Full Feature edition"); } [Conditional ("OFFLINE")] [Conditional ("ONLINE")] Public voidgetinfofromnet () {Console.WriteLine ("Standalone feature edition"); } } classProgram {Static voidMain (string[] args) {MyService service=NewMyService (); Service. Testing (); Service. Getinfofromnet (); } }
To implement two different functions, you need to define the file at the beginning of the program entry:
#define ONLINE
#define OFFLINE
This compilation symbol must be at the very beginning of the file. At the same time, the definition is valid only for this document. If you want to define a global compilation symbol, you must define it in the project properties.
If you want to define multiple global macro definitions, separate them with commas, such as "Offline,online".
If you want to publish all features, enter conditional compilation symbol # define ONLINE, and the code runs as follows:
Full version features
Standalone features
If you want to publish offline features, use # define OFFLINE. Run as follows:
Standalone features
Turn from: 157 recommendations for writing high-quality code to improve C # programs Minjia
"Go" writing high-quality Code 157 recommendations for improving C # programs--Recommendation 156: Using features to provide multiple versions of an application