【发布时间】:2015-02-15 14:50:38
【问题描述】:
我需要以下逻辑
#if (DEV || QA || RELEASE)
//add when dev or qa or release configuration
#endif
在c#中可以吗?
【问题讨论】:
标签: c# visual-studio custom-configuration
我需要以下逻辑
#if (DEV || QA || RELEASE)
//add when dev or qa or release configuration
#endif
在c#中可以吗?
【问题讨论】:
标签: c# visual-studio custom-configuration
是的。引用#if documentation on MSDN:
您可以使用运算符
&&(和)、||(或)和!(非)来评估是否定义了多个符号。您还可以使用括号对符号和运算符进行分组。
【讨论】:
#define DEBUG
#define MYTEST
using System;
public class MyClass
{
static void Main()
{
#if (DEBUG && !MYTEST)
Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
Console.WriteLine("DEBUG and MYTEST are defined");
#else
Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
}
}
这里有简单的代码如何做到这一点。你可以在C# Preprocessor Directives阅读完整的文档
【讨论】: