Hi,
I have been experimenting with getting code to be excluded by use of the Conditional attribute. The code I have been using couldn't be simpler, and is as follows:
class Program
{
static void Main( string[] args )
{
CallFunction();
}
[Conditional("TEST_SYMBOL")]
static void CallFunction()
{
int x = 1;
int y = 1;
_z = x - y;
_z /= _z;
}
private static int _z = 0;
}
When I build and run the application with TEST_SYMBOL defined, I get the expected divide-by-zero error, and when the symbol is not defined, I get no error. So far so good.
But when I examine the compiled assemblies on disk (with and without the symbol defined), both are exactly the same number of bytes; and when I examine them with Reflector, the code in CallFunction() appears to be present in both assemblies.
My understanding was that the Conditional attribute allowed code, not just to be called or not called, but also to be excluded if unused. Otherwise, it is just unnecessary code bloat in one of the assemblies.
Am I missing something here? Any help would be very much appreciated.
Best wishes, Patrick