http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx”rel=“noreferer”> ConditionsalAttribute
班级:
Applying ConditionalAttribute to a method indicates to compilers that a call to the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with ConditionalAttribute is defined.
对我来说,<条码>有条件条码>只能改变个人方法呼吁层次的行为。 但审议以下法典:
class InstanceType
{
public InstanceType DoSideEffects()
{
Console.WriteLine("Side effects!");
return this;
}
public InstanceType DoMoreSideEffects()
{
Console.WriteLine("More side effects!");
return this;
}
[Conditional("DEBUG")]
public void ConditionalMethod()
{
Console.WriteLine("Conditional method run.");
}
}
class Program
{
static void Main()
{
var x = new InstanceType();
// The compiler appears to strip out this entire line
// in a Release build.
x.DoSideEffects().DoMoreSideEffects().ConditionalMethod();
var y = new InstanceType();
// When each method call appears on its own line,
// the first two methods are included as expected.
y.DoSideEffects();
y.DoMoreSideEffects();
y.ConditionalMethod();
}
}
比较 De和排放物的产出可以:
DEBUG RELEASE Side effects! Side effects! More side effects! More side effects! Conditional method run. Side effects! More side effects! Conditional method run.
www.un.org/Depts/DGACM/index_spanish.htm 这种行为是否具体指明了什么地方? 我曾认为,这两个建筑的产量应当相同,但“有条件方法”二字除外。