What is the alternative to having code with conditional compilation in C#?
I have a class that has lots of code that is based on # ifdef .. After sometime my code is unr
An alternative is to use the ConditionalAttribute. The conditional attribute works in a similar way.
#define TRACE_ON
using System;
using System.Diagnostics;
public class Trace
{
[Conditional("TRACE_ON")]
public static void Msg(string msg)
{
Console.WriteLine(msg);
}
}
public class ProgramClass
{
static void Main()
{
Trace.Msg("Now in Main...");
Console.WriteLine("Done.");
}
}