"Go" writing high-quality Code 157 recommendations for improving C # programs--Recommendation 156: Using features to provide multiple versions of an application

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.