|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionI receive every month or so, a free magazine from VSJ. The articles in the magazine focus on "visual" languages such as Java, VB.NET, etc. Along with the articles, there is an "Outlook" section that discusses some recent developments or something similar, and also book reviews as well as the usual advertising. In the Feb 5th edition, there was an article entitled "Script it with C#" (you can read the original here). This article is a .NET 2.0 version inspired by the original VSJ article but duly rewritten from the ground up. BackgroundI contemplated changing the existing article to support the .NET 2.0 Framework back when it was still in Beta1, however when I tried this, it ran into a plethora of errors, and due to the time constraints, I dropped it. This evening, I decided that it would be nice if it did work under .NET 2.0 (just because of creating support for generics :) ) and so I did it. Using the codeIncluded inside the zip file are the source files (or should I say file) along with a VC# Express project to compile it with. However, because it's just a single file, you should be able to compile it quite easily using csc.exe. There are two routines inside the class, Main
private static void Main(string[] args)
{
// If no arguments then display error
if ((args.Length == 0) || (!File.Exists(args[0])))
{
MessageBox.Show("A script file must be provided" +
" on the command-line.", "No Script File",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
// Run the script (we'll leave the first argument so
// that the script knows where it is :)
CSScriptCompiler.RunScript(args[0], args);
}
}
RunScript
#using <namespace>This is analogous to the C# A possibility that crossed my mind was to use regular expressions to increase the robustness of parsing, however, I decided to opt out because it was easier and quicker to accomplish. #import <filename>I never got on well with Dino's system of using a separate file to reference the DLLs, the task is made much easier if all the code is contained within one source file and that's why I introduced the #include "filename"This is like the C Note: Remember to take this into account when debugging errors. I have not thought of an elegant solution which will keep track of the source files or line numbers. Points of interestAlong with the source / demo project is an installer created with NSIS which will register the .csx extension for the compiler so that when you run a script file, it automatically executes css.exe, the C# script compiler. It also associates an icon with the extension to identify the file-type. This installer will be compiled when you build the solution (if you have NSIS on your machine and installed in the default path). Here is a list of the main features of the application:
If anybody comes up with any cool or useful scripts that could be included with the source, then send me an email through the CP website and if they're good enough I'll include them in the zip. History
|
||||||||||||||||||||||