ito*_*son 16
在编译时还是运行时?在编译时,您可以使用#if DEBUG.在运行时,您可以使用它[Conditional("DEBUG")]来指示只应在调试版本中调用的方法,但这是否有用取决于您希望在调试版本和发布版本之间进行的更改类型.
static class Program
{
public static bool IsDebugRelease
{
get
{
#if DEBUG
return true;
#else
return false;
#endif
}
}
}
Run Code Online (Sandbox Code Playgroud)
虽然,我倾向于同意itowlson.
我个人不喜欢“#if debug”改变布局的方式。我通过创建一个仅在调试模式下调用并通过引用传递布尔值的条件方法来做到这一点。
[Conditional("DEBUG")]
private void IsDebugCheck(ref bool isDebug)
{
isDebug = true;
}
public void SomeCallingMethod()
{
bool isDebug = false;
IsDebugCheck(ref isDebug);
//do whatever with isDebug now
}
Run Code Online (Sandbox Code Playgroud)
我倾向于在 AssemblyInfo.cs 中添加类似以下内容:
#if DEBUG
[assembly: AssemblyConfiguration("Debug build")]
#else
[assembly: AssemblyConfiguration("Release build")]
#endif
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6875 次 |
| 最近记录: |