我知道,如果我有一个代码块,我不想在 Release模式下编译,我可以将该代码块包装在:
#if DEBUG
while(true)
{ Console.WriteLine("StackOverflow rules"); }
#endif
这将阻止此代码块以
DEBUG
以外的任何模式编译。 .我知道有一个属性可以放在一个可以做同样事情的整个方法上,但是对于我来说,我不记得那个属性是什么了。我相信它在
System.Diagnostics
下命名空间,但我不太确定。顺便说一句:我使用的是 .NET 4,但我知道这个属性存在于 .NET 2 中,因为我在旧项目中使用过。
谢谢
最佳答案
Indicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined.
您应该将其定义为
[Conditional("DEBUG")]
并确保未在 Release模式下定义 DEBUG 常量。
关于.net - 在 Release模式下不编译方法的 .NET 属性是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2803300/