Note that there are some explanatory texts on larger screens.

plurals
  1. POIs ConditionalAttribute supposed to strip out entire lines, or just method calls?
    primarykey
    data
    text
    <p>According to the documentation on the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx" rel="noreferrer"><code>ConditionalAttribute</code></a> class:</p> <blockquote> <p>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.</p> </blockquote> <p>To me this is saying that the <code>Conditional</code> attribute only alters behavior at the individual method call level. But consider the following code snippet:</p> <pre><code>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(); } } </code></pre> <p>Compare the outputs of Debug and Release builds:</p> <pre> DEBUG RELEASE Side effects! Side effects! More side effects! More side effects! Conditional method run. Side effects! More side effects! Conditional method run. </pre> <p><strong>Is this behavior specified somewhere?</strong> I had thought that both builds were supposed to have the same output except for the lines reading "Conditional method run."</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload