使用ConditionalAttribute是否还会删除参数计算? [英] Does using ConditionalAttribute also remove arguments computation?
问题描述
我尝试了以下代码:
class Magic {
[Conditional("DEBUG")]
public static void DoMagic( int stuff )
{
}
public static int ComputeMagic()
{
throw new InvalidOperationException();
}
}
class Program
{
static void Main(string[] args)
{
Magic.DoMagic(Magic.ComputeMagic());
}
}
看起来在Release build中不是这样抛出的结果不仅删除了对标记为 ConditionalAttribute
的方法的调用,而且消除了参数计算。
and it looks like in Release build the exception is not thrown so not only the call to a method marked with ConditionalAttribute
is removed, but also the parameters computation is eliminated.
这样的行为是否得到保证?
Is such behavior guaranteed?
推荐答案
是的,当 DEBUG $ c $时,参数评估被删除。 c>未定义(这在发行版中很常见)。
Yes, argument evaluation is removed when DEBUG
is not defined (which is typical in Release builds).
来自 http://msdn.microsoft.com/zh-cn/library/aa664622%28v=vs.71%29.aspx :
如果定义了符号,则包括该调用;否则,将忽略呼叫
(包括对呼叫参数的评估)。
If the symbol is defined, the call is included; otherwise, the call (including evaluation of the parameters of the call) is omitted.
这篇关于使用ConditionalAttribute是否还会删除参数计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!