System.Diagnostics.ConditionalAttribute and conditionally compiling supporting types and variables
<p>In a class, I've got a trace method that looks like this: </p>

<pre><code>    [System.Diagnostics.ConditionalAttribute("Trace")]
    private void TraceOutput(TraceBits bits, string format, params object[] varParams)
    {
        if ((bits &amp; _DesiredTrace) != 0)
        {
           ...emit trace here...
        }
    }
</code></pre>

<p>TraceBits is a <code>[Flags] enum</code>.  Each call to TraceOutput passes in the bit that the call is tagged with.  Like this: </p>

<pre><code>    TraceOutput(TraceBits.Fill,
                "Fill     lock     wi({0}) stat({1}) iba({2}) nf({3})",
                workitem.index,
                workitem.status,
                workitem.inputBytesAvailable,
                _nextToFill
                );
</code></pre>

<p>The bits are: Create, Read, Write, Fill, etc.   _DesiredTrace is a (private member variable) bitfield that indicates which trace statements should be actually emitted.  This way I can selectively turn on trace statements for various portions of function within the class. If I want to trace only construction and destruction, I set the Create bit in that member bitfield.</p>

<p>I can use the <code>ConditionalAttribute</code> on the method, but that attribute doesn't work on member variables or nested types (like TraceBits). </p>

<p>As a result, the types and variables that support tracing, are compiled into the code, whether or not <code>Trace</code> is defined.  If Trace is undefined then these are completely unnecessary.</p>

<p>Is there a clean way to conditionally compile the supporting types and variables in? </p>

<p>I know I can use <code>#if Trace ... #endif</code>  to surround the declaration and all invocations of TraceOutput, as well all the supporting stuff, but that uglifies the code.  I like the cleaner look of the <code>ConditionalAttribute</code>, where each call to TraceOutput does not need to be bracketed with <code>#if Trace</code>.  </p>

<p>What I really want is some way to use that attribute, or something like it, on nested classes and member variables.  Is that possible? </p>
