gpt4 book ai didi

c# - 停止错误发布编译的优雅方法

转载 作者:可可西里 更新时间:2023-11-01 03:05:50 26 4
gpt4 key购买 nike

在开发过程中,您经常会使用诸如

throw new NotImplementedException("Finish this off later") 

// TODO - Finish this off later

作为一个占位符来提醒您完成一些事情 - 但这些可能会被遗漏并错误地出现在发布中。

你可以使用类似的东西

#if RELEASE
Finish this off later
#endif

所以它不会在 Release build 中编译 - 但有没有更优雅的方法?

最佳答案

我看到了一个优雅的实现 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

关于c# - 停止错误发布编译的优雅方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9162157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com