Start a new topic

Just a little electron from C#

Since docs are still in the future, I've started creating a binding to electron.  This is "just enough" code to get electron to open a window but demonstrates how to create such a binding and use it to that degree:

Here is a tiny bit of electron.d.cs:

// Partial type definitions for Electron

// Project:

using System;

using DuoCode.Dom;

using DuoCode.Runtime;

#pragma warning disable 0626 // disable: method is marked external and has no attributes on it

#pragma warning disable 0824 // disable: constructor 'ctor' is marked external

namespace electron


 [Js(Extern = true)]

 public class App : NodeJs.Events.EventEmitter




 [Js(Extern = true)]

 public class BrowserWindow


  // Constructor takes JSON paramaters, this appears to be how you do that (?)

  public extern BrowserWindow(object param);




And here is some code using it:

using System;

using DuoCode.Dom;

using DuoCode.Runtime;

using electron;

using NodeJs;

namespace DuoCodeElectronTest


 static class index


  [Js(InvokeMainMode = InvokeMainMode.Immediate)]

  static void Main()


   System.Console.WriteLine("Starting Electron App ");

   var app = Js.require<App>("app");

   var BrowserWindow = Js.require<BrowserWindow>("browser-window");

       dynamic mainWindow = null;

  app.@on("ready", new Action(() =>


    System.Console.WriteLine("APP READY EVENT");

    // This appears to be how you define JSON for passing around to functions that expect it

    var win = new BrowserWindow(Js.referenceAs<dynamic>(@"{width: 800, height:600}"));


    MainWindow mw = new MainWindow();





This works, in so far as it goes.  Next thing to figure out is how to emit more than just a single .js file.

Please have look at


 method found in DuoCode.Runtime, which creates a JavaScript object expression (like: <c>{ prop1: value1, prop2: value2 }</c>) using anonymous class declaration.


Js.@object(new { prop1 = value1, prop2 = value2 })


That does seem to be a bit better.

Given how tickets are not answered, and lack of activity... I'm assuming this project is either dead or dying.  Sad too, shows so much promise.

Hi David,

I'd like to assure you DuoCode is definitely alive and well! I understand this is no excuse for the late replies, but we're definitely cranking up some advancements in the compiler and the tooling.

We just launched the online Try DuoCode site, and we're about to release a new version.

We definitely need to improve our presence in the forums (and general support), we're make it better, promise! :)

Using Js.@object() is srongly typed and allows to refer variables or even call methods. For example:    

int w = 800;
var win = new BrowserWindow(Js.@object(new { width = w, height = CalcHeight()}));


Well I apologize and am happy you guys are working diligently on this.  I do believe it is an amazing piece of work and would be my go-to tool.

I know it is early, but you know how it is... you see lots of new tech and you have to evaluate if it's going anywhere before you invest much time in it (much less money).  One big way is to see what the responsiveness of the developers are, and that's what I based that on.

It is worth noting, though, that the one 'support ticket' I submitted (and referenced above) still has no answer.

I'd make sure those get priority, and documentation as well.  It really needs that in order to do anything practical.  Trying to hack it out is ..... limiting... to say the least.



This works, in so far as it goes.  Next thing to figure out is how to emit more than just a single .js file.

dcc compiles whole assembly to one .js file, similar to this mapping .dll -> .js, and .pdb ->

You can use classic multiple assemblies approach in your project/solution and refer either project reference or assembly reference to other assemblies. Use "Copy Local" wisely or compile them to one target folder.

You can even use Assembly.Load() translates to require() to "load" assembly/module at runtime.

Most def Js.Object is the one to use... Here is a quick snippet of some Webix bindings that makes use for 

anonymouse object for configs (The whole webix api uses anonymous javascript objects for everything)

take a look at the C# version (There is even some code using AJAX-RPC for a more native RPC style

of services as apposed to  bunch of string build URL that you you have to manually POST or GET):

public static void Run()
// Create name text and send button
Webix.ui(Js.@object(new { container = Root.get("nameFieldContainer"), view = "text", id = "nameText", value = "Gateway User", width = 175 }));
Webix.ui(Js.@object(new { container = Root.get("sendButtonContainer"), view = "button", id = "sendButton", value = "Send", width = 75 }));

// Attach button on item click event
WebixObject btn1 = Webix.get<WebixObject>("sendButton");
btn1.attachEvent("onItemClick", (Action<string>)(id => {
Webix.message("SenderID: " + id);

// Get user name to send to server
WebixObject txt1 = Webix.get<WebixObject>("nameText");
string textToServer = txt1.getValue();

// Execute remote greeting service
GreetingService svc = new GreetingService();
System.Console.WriteLine("Calling remote service...");
svc.greetServer(textToServer, new MethodCallback<string>(
(string result) => {
System.Console.WriteLine("Result: " + result);
Webix.message(Js.@object(new { type = "default", text = result, expire = 10000 }));
} , (Exception error) => {
System.Console.WriteLine("Error: " + error.Message);
Webix.message(Js.@object(new { type = "error", text = "Error: " + error.Message, expire = 10000 }));

Mackey, that looks great! :)

As a matter of fact... here is what i got so far (I know its not d.cs... because this was going to be part of my toolkit... and im not to keen on the whole typescript stuff... i dont even like typescript... C#... thats why i fell in love with DuoCode..):

So far DuoCode is the BEST commercially backed, actively developed, Roslyn based C# - To Javascript compiler out there. Ive look at them all ... From The Old SharpKit... to the Wootz (Which is also Rosyln based... but NOWHERE near the features you get with DuoCode)

OH YEAH... DID I FORGET TO SAY... Commercially and Actively Developed!!!

I have been waiting for this for sooo long... having to use Google Web Toolkit and Java sucks for a C# guy like myself...

Anyways... anybody else trying to make bindings, here is what i got so far for My Webix implementation


(11.9 KB)

More like "pre-commercial"... not sure there is anyway to compensate the developers for their hard work yet. :)

Login or Signup to post a comment