Thursday, October 21, 2010

Conditional Method

// CondMethod.cs
// compile with: /target:library /d:DEBUG
using System;
using System.Diagnostics;
namespace TraceFunctions
{
public class Trace
{
[Conditional("DEBUG")]
public static void Message(string traceMessage)
{
Console.WriteLine("[TRACE] - " + traceMessage);
}
}
}





// TraceTest.cs
// compile with: /reference:CondMethod.dll
// arguments: A B C
using System;
using TraceFunctions;

public class TraceClient
{
public static void Main(string[] args)
{
Trace.Message("Main Starting");

if (args.Length == 0)
{
Console.WriteLine("No arguments have been passed");
}
else
{
for( int i=0; i < args.Length; i++)
{
Console.WriteLine("Arg[{0}] is [{1}]",i,args[i]);
}
}

Trace.Message("Main Ending");
}
}

No comments: