For the following reasons, you must provide multiple versions for the application:
1: The application has a trial version and a full functional version;
2: Automated operations are required during application testing;
1: Trial Edition
For the first point, the experience version is a small version of the full version. That is, for some reason, all functions of the application are not available to users.
Assume that my application has two types of functions. The first type of features belong to the standalone version, and the full version also provides online features. In terms of functions, I need to customize two attributes: "ONLINE" and "OFFLINE ". In the trial version, I only open the "OFFLINE" function.
To achieve this, I don't want to provide two sets of applications. Instead, I want to output Two Release versions for one application through the minimum setting. In this case, the Attribute in. NET is required.
First, we simulate two functions: offline and online:
Code
class MyService
{
[Conditional("OFFLINE")]
[Conditional("ONLINE")]
public static void Testing() { System.Windows.Forms.MessageBox.Show("offline game..."); }
[Conditional("ONLINE")]
public static void GetInfoFromNet() { System.Windows.Forms.MessageBox.Show("online game..."); }
}
Program entry:
Code
private void button1_Click(object sender, EventArgs e)
{
MyService.Testing();
}
private void button2_Click(object sender, EventArgs e)
{
MyService.GetInfoFromNet();
}
To implement two different functions, you must define them in the program entry file:
#define ONLINE
//#define OFFLINE
using System;
using System.Collections.Generic;
using System.ComponentModel;
1.1: global macro definition
Remember, this definition must be at the beginning of the file. At the same time, this definition is only valid for this file. If you want to define a global one, it must be defined in the project properties as follows:
If you want to define multiple global macro definitions, separate them with commas, for example, "LUMINJI, HUCHANGJUN ".
The next question is simple. If you want to publish a full feature, # define ONLINE. If you want to publish an OFFLINE feature, comment out # define ONLINE and define OFFLINE.
2: Provides automated operations for the test process
When testing the UI, You need to operate on various text boxes, lists, and other controls. For example, in a logon window, you must enter the user name and password. Every time I test, I have to input it myself, which will inevitably affect the efficiency. In this case, Attribute can be used.
In the following example, in the Load event of the login window, we assign values to the user name and password, and simulate the Click event.
Code
#define TESTAUTO
using