-
Notifications
You must be signed in to change notification settings - Fork 7
Whatissssit HowItWorkz?
Warning: this article is somewhat sloppily-written. sorry about that. it should still give you the gist of how sharpjs works
SharpJS - is a collection of frameworks and libraries in itself how it works:
sharpjs uses a project called JSIL, which can roughly translate IL into JS then..what is IL???
so C# code gets compiled to IL, which is .NET Virtual Machine bytecode
this IL gets put in a DLL.
IL looks like this:
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 2
.locals init (
[0] int32 num)
L_0000: ldc.i4.0
L_0001: stloc.0
L_0002: br.s L_000e
L_0004: ldloc.0
L_0005: call void [mscorlib]System.Console::WriteLine(int32)
L_000a: ldloc.0
L_000b: ldc.i4.1
L_000c: add
L_000d: stloc.0
L_000e: ldloc.0
L_000f: ldc.i4.s 10
L_0011: blt.s L_0004
L_0013: ret
}
not what you want to write
because you have to write in what's basically assembly language
so the #JS compiler opens a DLL or EXE you tell it to compile. It opens the EXE and checks if it contains IL (all C# exe's contain IL, but C++ programs won't be compiled to IL unless using C++/CLI, but that isn't relevant)
Then it uses Mono.Cecil to read through this IL.
finally, it translates the IL to JavaScript, which you can find in all of the js
files in the output folder.
This awesome .NET CIL to JS is done by JSIL, an awesome open-source project!
SharpJS builds upon the JSIL toolchain by providing a unifiied API to interact with the DOM and design rich UI applications with a mix of C# and JS. Everything ends up as JS/HTML/CSS that you can run in any modern browser.
Additionally, JSIL is focused on porting games (specifically XNA games) to the web. SharpJS goes in a different direction, aiming instead to bring C# code and UI to the browser.
Around the time I started working on this project, I also discovered that http://www.cshtml5.com was working on a similar product. However, their product is proprietary, while SharpJS is open-source. You are welcome to use SharpJS in any way you please as long as you abide by its license: Apache 2.0; you may modify the code, extend the libraries, and more!
Right now, I'm working on a XAML/Material Design inspired UI framework that should be ready soon. More info will be available soon.
SharpJS.Dom
bridges the gap between JS/HTML and C#, allowing you to program div
s and other elements with C#.
ExaPhaser.WebForms
uses the libraries in SharpJS.Dom
to expose a simple user-interface API, allowing the end user to write pure C#, while the two framework layers take care of interaction with native web technologies.
The latest addition, WinFormsCompat
, exposes an API that matches that of traditional Windows Desktop C# applications. This allows you to compile unmodified source code initially written for Windows and run it in a modern browser. Under the hood, WinFormsCompat
is basically ExaPhaser.WebForms
in disguise, proxying calls and properties and events, but the WinForms application could care less, as the API is exactly the same.
You're helping build a framework that could potentially help to port tons and tons of desktop apps to run in the browser.
Additionally, instead of using JS, you can translate whole .NET libraries and run apps that usually exist only on the desktop in the browser.
There is no technology that really equals WinFormsCompat
available right now. There a closed-source package called VisualWebGUI
, but even that is an ASP.NET
app in disguise, meaning that you won't be able to run that from a local filesystem or serve it on a server like Apache.
SharpJS is the best because all applications are compiled to pure HTML5/JS, all client-side code, so you can run it off your local filesystem or any old server that can serve files. It's also completely open source!