John Smith <so*****@microsoft.com> wrote:
Thank you for the clear and concise answer. Public class libraries seem the
reason d'etre for the Conditional Attribute.
Just to clarify when you say the compiler quietly turns them into nops you
mean the JIT compiler, not the compiler than translates C# into IL.
No. For instance:
using System;
using System.Diagnostics;
class Test
{
static void Main(String[] args)
{
ConditionalTest();
}
[Conditional("CONDITION")]
static void ConditionalTest()
{
}
}
Compiling normally, the IL for Main is:
..method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 1 (0x1)
.maxstack 0
IL_0000: ret
} // end of method Test::Main
Compiling with CONDITION defined, the IL for Main is:
..method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 6 (0x6)
.maxstack 0
IL_0000: call void Test::ConditionalTest()
IL_0005: ret
} // end of method Test::Main
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too