当你在开发的时候,你经常会用到这样的东西
throw new NotImplementedException("Finish this off later") 或
// TODO - Finish this off later作为一个占位符,提醒你完成一些事情--但这些可能会被遗漏,并错误地在发布中结束。
您可以使用类似于
#if RELEASE
Finish this off later
#endif所以它不会在发布版本中编译--但是有没有更优雅的方式呢?
发布于 2012-02-06 23:17:37
我看到了一个优雅的实现here
#if DEBUG
namespace FakeItEasy
{
using System;
using System.Diagnostics.CodeAnalysis;
/// <summary>
/// An exception that can be thrown before a member has been
/// implemented, will cause the build to fail when not built in
/// debug mode.
/// </summary>
[Serializable]
[SuppressMessage("Microsoft.Design",
"CA1032:ImplementStandardExceptionConstructors",
Justification = "Never used in production.")]
public class MustBeImplementedException
: Exception
{
}
}
#endif发布于 2012-02-06 23:10:05
我建议使用#warning
#warning Finish this off later在Release配置中,将Treat Warnings as Errors设置为True。
在这种情况下,在Debug中,您将只看到警告,但在release中,它将抛出异常。
发布于 2012-02-06 23:10:52
您可以使用#error和#warning指令抛出自己的构建错误和警告:
#if RELEASE
#error Not finished!
#endifhttp://msdn.microsoft.com/en-us/library/c8tk0xsk(v=vs.80).aspx
https://stackoverflow.com/questions/9162157
复制相似问题