Hi,
I have pasted the code below.
This sub is getting a temp file name......can someone please explain me this code from the #If DEBUG_IO line.
Any help will be appreciated!!!
private static string getTempFileName(string Type, string Server, string Time, string InputFile)
{
string tempPath = null;
#if DEBUG_IO
tempPath = debugoutput;
if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
#else
tempPath = Path.GetTempPath();
#endif
return string.Format("{0}{1}-{2}-{3}-{4}-{5}", tempPath, Type, Server.Replace(':', '-'), Time.Replace('/', '_').Replace(' ', '_').Replace(':', '_'), Guid.NewGuid().ToString("N"), Path.GetFileName(InputFile));
}
I'm dusting off some cobwebs in the far reaches of my mind but I'll try to help you understand the following code:
-
#if DEBUG_IO
-
...
-
#else
-
...
-
#endif
-
The #if directive is read by the pre-compiler.
The pre-processor (pre-compiler) checks your code and splits it up into sections. It's kind of complicated and I learned this a long time ago so please bear with me me here:
Your DEBUG_IO variable will be defined as a Directive....for instance, since you're not in debug mode it would be defined as:
...you can set this to True and debugging code will be executed....otherwise the debugging code is ignored.
I remember the preprocessing directives in my C and C++ projects I created for multiple platforms: eg. if my program were running on Windows, I would include a certain set of libraries and if it was run on Unix, I would include a completely different set of libraries...
-
#define OS 'Windows'
-
...
-
#if OS == 'Windows'
-
include ...windows libraries
-
#else
-
include ...unix libaries.
-
#endif
-
-
This way when I compiled my code, the pre-processor would look at my directives and only give to the compiler anything that is relevant...so, anything pertaining to the other operating system would be ignored by the compiler at compile time...
Does this make sense?
Look up Preprocessing and #if directives. It's been a long time since I've used this stuff and don't know if I've been helpful.
-Frinny