KBJ
09-02-2007, 03:21 PM
Yesterday I got mixed up while debugging, because I had the wrong version of an indicator on my test system.
So, I decided to build something into the indicator to display the current version number and the build date & time, like I do with other applications written in C++ on other platforms.
And I found that C# has no simple equivalent to the C++ built-in constants of "__DATE__" and "__TIME__", which will very simply put string values containing the date & time that the last build was done into the object file generated by the compiler.
But, after much searching (I thought this project was going to take 12 seconds, boy was I wrong), I found the following code that's supposed to display the version number and date and time of a C# Assembly:
System.Reflection.Assembly assem = System.Reflection.Assembly.GetExecutingAssembly(); // Get a pointer to the assembly for the current routine.
Version vers = assem.GetName().Version; // Get the version of that assembly.
DateTime buildDate = new DateTime(2000, 1, 1).AddDays(vers.Build).AddSeconds(vers.Revision * 2); // Build time is relative to 1/1/2000
Print( "Version=" + vers.ToString() + " DateString=" + buildDate.ToString() ); // Display message in NinjaTrader's Output window.
However, what it displays has nothing to do with the indicator I'm developing. It displays the following in the Output window:
Version=6.0.1000.4 DateString=9/27/2002 12:00:08 AM
Since the version number is that of NinjaTrader, I'd expect the date to somehow or other be related, but its not.
What I really want is what C++ provides... that the compiler embeds the date & time information into its output file, so that when I run the program, the program can display the time that it was last built.
Is there any way that I can display the time of the last compile of my indicator or strategy?
If not, would you consider adding something like this in the future? (i.e., embedding the compile date & time into each indicator and strategy module and providing a way to reference it at runtime as a Double or String or DateTime)
So, I decided to build something into the indicator to display the current version number and the build date & time, like I do with other applications written in C++ on other platforms.
And I found that C# has no simple equivalent to the C++ built-in constants of "__DATE__" and "__TIME__", which will very simply put string values containing the date & time that the last build was done into the object file generated by the compiler.
But, after much searching (I thought this project was going to take 12 seconds, boy was I wrong), I found the following code that's supposed to display the version number and date and time of a C# Assembly:
System.Reflection.Assembly assem = System.Reflection.Assembly.GetExecutingAssembly(); // Get a pointer to the assembly for the current routine.
Version vers = assem.GetName().Version; // Get the version of that assembly.
DateTime buildDate = new DateTime(2000, 1, 1).AddDays(vers.Build).AddSeconds(vers.Revision * 2); // Build time is relative to 1/1/2000
Print( "Version=" + vers.ToString() + " DateString=" + buildDate.ToString() ); // Display message in NinjaTrader's Output window.
However, what it displays has nothing to do with the indicator I'm developing. It displays the following in the Output window:
Version=6.0.1000.4 DateString=9/27/2002 12:00:08 AM
Since the version number is that of NinjaTrader, I'd expect the date to somehow or other be related, but its not.
What I really want is what C++ provides... that the compiler embeds the date & time information into its output file, so that when I run the program, the program can display the time that it was last built.
Is there any way that I can display the time of the last compile of my indicator or strategy?
If not, would you consider adding something like this in the future? (i.e., embedding the compile date & time into each indicator and strategy module and providing a way to reference it at runtime as a Double or String or DateTime)