当DEBUG=true时使用方法参数的任何方式,类似于ConditionalAttribute,但用于参数



当DEBUG=true时使用方法参数的任何方式,类似于ConditionalAttribute,但用于参数:

static void Recursion(int depth)
{
//.. some code here
// .. Recursion(depth); ..
}

对于我的例子,我需要这样的:

Recursion([ConditionalParameter("DEBUG")] int depth)

你可以这样做:

static void Recursion(
#if DEBUG
int depth
#endif
)
{
//.. some code here
// .. Recursion(depth); ..
}

但我不推荐。

我认为您应该将Debugger.IsAttachedif语句结合使用:

public void Recursion(int depth) {
if (Debugger.IsAttached) {
//do something with depth
}else {
//do something without depth
}
}

最新更新