When I read general description of Script#, I thought “Wow how simple it is!”. I need just to write some code on C#, compile my application, get the needed JavaScript files which stably work in all browsers. And I don’t need to think of DOM model of browsers, and especially differences among them – I can do everything on C#. Script# supports such library as jQuery. And this, to my mind, is a key benefit. The second thing that impressed me is that I don’t need to spend a lot of time reading tons of docs to start working with Script#. My average knowledge of JavaScript and C# is enough.
After two month of our “intimate relationships” with Script# – I can say that I love it ! Script# fully satisfied my expectations. It allowed me to quickly create the project, and, what is the most important, to get as a result qualitative, stable and pure JavaScript code.
And now, I’d like to explain what the Script# technology includes:
- ssc.exe compiler which converts the code written in C# into *.js files.This is a .Net compiler which creates JavaScript instead of MSIL. Depending on the choice of the debug mode, different types of files are created. This can be either XXX.debug.js files (they reflect the application structure and are convenient for debug) or XXX.js files (they are compressed due to throwing away unnecessary whitespaces, they are hardly readable, but “lite”).
- Libraries of basic types and classes of Script#: mscorlib.dll, Script.jQuery.dll, Script.Windows.dll, Script.Web.dll, and some others.
Basic libraries allow the use of familiar .Net types (Byte, Int16, Int32, DateTime) and classes, for example, StringBuilder or CultureInfo. Besides that they contain classes to manage an application
(the Application class and connected to it dispose mechanisms, session management, scripts loading, etc.). The libraries allow us to exchange data with web server (the HttpRequest \ HttpResponce classes) or use familiar management elements like Button or TextBox. - Libraries of API support for such technologies as ASP.Net AJAX, Bing Maps, Silverlight and so on.These libraries add support for the object models of the listed above technologies. Thus, it is possible to use the objects, let’s say from Bing Maps, in C# code and, at this, get the full power of IntelliSense support.
- Different templates of projects and items for Visual StudioWhen Script# is installed, new project types are available. These types are Script# enabled Web-site”, “Script# class library” or “Sidebar Gadget”.
The work of Script# can be shown as follows:
http://projects.nikhilk.net/ScriptSharp/Conceptual-Understanding:
- I write the code on Script# using familiar classes and management elements of ASP.Net.
- The C# compiler checks the types and the code correctness. But, it is necessary to add references to the Script# libraries and remove references to the standard .Net libraries (for example mscorlib.dll, the same name as in .Net). It is obvious that it is impossible to convert all that I could write in C# into ASP.Net. That’s why, we can take that basic Script# mscorlib.dll library is a simplified variant of .NET mscorlib.dll library. mscorlib.dll contains redefinition of standard .Net types and classes which Script# can convert into scripts.
The Script# compiler creates the JavaScript files by compiling the C# constructions you used into analogous JavaScript constructions. Thus, classes and process of inheritance are implemented with use of prototype concept in JavaScript. For example, the code like this in C#:
- You add the generated scripts and also refernces to basic library of Script# scripts to the needed ASP.Net page:
{
public class Employee : Person
{
public Employee(string name) : base(name) { }
}
}
will be converted into the following code on JavaScript:
Demo.Employee = function(name)
{
Demo.Employee.initializeBase(this, [ name ]);
}
Demo.Employee.createClass(“Demo.Employee”, Demo.Person);
<script src=”Scripts/mscorlib.js” type=”text/javascript”></script>
<script src=”Scripts/Demo.js” type=”text/javascript”></script>
Besides the standard classes and mechanisms, Script# is constantly extending with libraries of APIs of other technologies. Now I can name:
- Bing Maps API (Script.Microsoft.BingMaps.dll) – support for Bing Maps;
- Sidebar Gadgets (Script.Windows.dll) – Script# can be used to program gadgets for Windows Vista by referencing the Gadget APIs, RSS Feed APIs and File System APIs in addition to the default DHTML DOM APIs.
Thus, I can write high-level code using IntelliSence, and then the compiler generates all the needed scripts which refers to script API of these solutions. And what impressed me much is that all the mentioned above extensions were added after the first release of Script#.