Syed Umar Anis.NetConvert C# code to JavaScript
Syed Umar Anis.NetConvert C# code to JavaScript

Update June 2019: Five years on, each one of the following projects is either discontinued or stale for years. While Bridge.Net has been active for many years and doing pretty well.

There are some tools which convert C# code to JavaScript. Obviously, these will only be useful if your code is not tightly coupled with any C# library as the library won’t be available in JavaScript. These conversion tools may come handy for model classes or any other logic which is, for the most part, independent of .Net framework classes.

The main focus of these tools is not code conversion, rather they primarily try to do for C# what GWT does for Java. They allow you to write code in C#, access the DOM and JavaScript libraries to develop web applications. When the code is compiled, the output is not .Net Application but a web application written in JavaScript and HTML.

Conversion Tool Description
duocode duocode is a new tool on the block, currently in beta. It is going to be a commercial software but free to use as of now. duocode uses Microsoft Roslyn and support debugging C# code your compiled JavaScript is running in the browser. It supports pretty comprehensive set of C# feature including Await/Async, C# 6.0 language features, resource files etc.

Homepage: http://duoco.de/

SharpKit SharpKit is commercial (free for open source & small projects) as opposed to the alternatives listed below but does an excellent job of converting C# to JavaScript which is clean and readable. Moreover, it supports all features of C# language.You can see SharpKit live in action here. Give it a C# class or a snippet, it will convert it to JavaScript right there.Sharpkit compares itself with JSC, Script# and GWT at http://sharpkit.net/Compare.aspx

Homepage: http://sharpkit.net/
Google Code: https://code.google.com/p/sharpkit/

JSIL JSIL is a compiler that transforms .NET applications and libraries from their native executable format (CIL bytecode) into standards-compliant, cross-browser JavaScript.There are quite a few demos on JSIL website, one of them allows you to convert C# code to JavaScript right in the browser (though the generated code looks a bit obscure).

Homepage: http://jsil.org/
GitHub: https://github.com/sq/JSIL

JSC JSC is an Open Source cross-compiler where you can create web applications for Java, JavaScript, Flash ActionScript, PHP and Google App Engine using Microsoft .NET in C#, VB or F#. And also integrates into the .NET frameworks, Silverlight and ASP.NET.

Homepage: http://www.jsc-solutions.net/
Wiki & Tutorials: http://wiki.jsc-solutions.net/
Sourceforge: http://sourceforge.net/projects/jsc/

Script# Script# is a compiler that generates the JavaScript instead of MSIL (Microsoft Intermediate Language) from C# source code like GWT (Google Web Toolkit).Script# supports a subset of language features, for instance, enum and struct are not supported.

Homepage: http://scriptsharp.com/
GitHub Repository: https://github.com/nikhilk/scriptsharp

Saltarelle Saltarelle is an open source C# to JavaScript compiler. Saltarelle is not an entire framework for web application development (such as GWT), rather it consists of a compiler and a small runtime library that only contains the things necessary for the language features to work. It is, however, designed with interoperability in mind so you can use any existing JavaScript framework with it. It comes with support for jQuery, and other libraries can be used either by authoring an import library (which is just a class/set of classes with special attributes on their members) or by using the ‘dynamic’ feature of C# 4.

Homepage: http://www.saltarelle-compiler.com/
Git Repository: https://github.com/erik-kallen/SaltarelleCompiler

For a comprehensive list of tools that convert C# and other languages to JavaScript, visit https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS

Hi, I’m Umar

6 Comments

  1. sharp2Js

    Here’s one that I created, if helpful. Its open-source, and designed to create javascript objects from C# DTO classes. It’s not a full-fledged language translator, but can be pretty useful for working with Web API, and other .Net technologies. Let me know if there are any questions I can answer.

  2. using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.Remoting.Metadata.W3cXsd2001;
    using System.Text;
    using System.Threading.Tasks;
    namespace ConsoleApp1
    {
    class Program
    {
    static void Main(string[] args)
    {
    GetFileNameAndWriteInTxt();
    }
    public static void GetFileNameAndWriteInTxt()
    {
    string path = @”C:\Users\v-sanumu\Desktop\New folder”;
    DirectoryInfo dr = new DirectoryInfo(path);
    FileInfo[] mFile = dr.GetFiles();
    string a;
    string b;
    DateTime dob;
    int age;
    foreach (FileInfo fiTemp in mFile)
    {
    a= fiTemp.Name;
    b = a.Substring(0,10);
    dob = Convert.ToDateTime(b);
    var today = DateTime.Now;
    if(dob.Month>today.Month)
    {
    age =Convert.ToInt32( today.Year – dob.Year – 1);
    }
    else if(dob.Monthtoday.Date)
    {
    age = Convert.ToInt32(today.Year – dob.Year – 1);
    }
    else
    {
    age = Convert.ToInt32(today.Year – dob.Year);
    }
    }
    if (age>=18)
    {
    Console.WriteLine(fiTemp.Name);
    }
    }
    Console.Read();
    }
    }
    }

Leave a Reply to Umar Cancel reply

Your email address will not be published. Required fields are marked *