[英]How can I change #define
例如,当用户输入一些注册密钥时,如何将#define TRIAL更改为#define PREMIUM。
谢谢。
//#define TRIAL
#define PREMIUM
using System;
using System.Diagnostics;
using System.Reflection;
namespace Attributes
{
[Obsolete("This is an old class. Use new class instead!")]
class Test
{
[Conditional("TRIAL")]
void Trial()
{
Console.WriteLine("Trial");
}
[Conditional("PREMIUM")]
void Release()
{
Console.WriteLine("PREMIUM");
}
......................................
听起来您可能误解了预处理程序指令。 您应该将这种信息以某种方式存储在用户的计算机上,然后将其加载到变量中,或者更好的是,发布两个版本以进行升级。 这样会更加稳定和安全。
如果选择采用这种方法,则可以在此使用预处理器指令为程序的每个发行版编译不同版本的库和代码。
#define是编译时指令,因此您不能使用它...相反,如果出现以下情况,则应使用旧版本:
class Test
{
void DoAction() {
if(trial) { Console.WriteLine("Trial"); }
else { Console.WriteLine("PREMIUM");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.