To create methods that will only be called in a debug build of your application, you can use the following syntax :
[Conditional( “DEBUG” )]
private void SetDebugVariables()
{
connect
ionString = “datasource=developmentDB;SSPI=true;initial catalog=development”;
Trace.WriteLine(“Called in debug build”);
}
One use is to override release build settings to allow you to reference a local data store instead of the production data.
private function setVariables(){ connectionString = "datasource=productionDB;SSPI=true;initial catalog=production"; SetDebugVariables(); } [Conditional( "DEBUG" )] private void SetDebugVariables() { connectionString = "datasource=developmentDB;SSPI=true;initial catalog=development"; Trace.WriteLine("Called in debug build"); }
In a debug build, the method SetDebugVariables() is called, and will therefore override the default (reslease) settings. In a release build, the call to SetDebugVariables() is never made. This is because the compiler recognises the Conditional nature of the method, and simply ignores calls to it in a release build.