CSharpToJavaScript 0.0.1
Use .Net 8 version(0.0.06+).
.Net 7 versions will soon be unlisted.
See the version list below for details.
dotnet add package CSharpToJavaScript --version 0.0.1
NuGet\Install-Package CSharpToJavaScript -Version 0.0.1
<PackageReference Include="CSharpToJavaScript" Version="0.0.1" />
paket add CSharpToJavaScript --version 0.0.1
#r "nuget: CSharpToJavaScript, 0.0.1"
// Install CSharpToJavaScript as a Cake Addin
#addin nuget:?package=CSharpToJavaScript&version=0.0.1
// Install CSharpToJavaScript as a Cake Tool
#tool nuget:?package=CSharpToJavaScript&version=0.0.1
CSharpToJavaScript
Brute forcing conversion(translation) from C# to Javascript.
This is a personal project with purpose to learn and understand better c# and js at the same time. Many stuff is not supported and some won't. Updates will be happening when I'm using this library.(irregular)
C#
using static CSharpToJavaScript.APIs.JS.GlobalThis;
namespace ConsoleAppTest.CSharp;
public class Test
{
public Test()
{
Console.Log("HelloWorld!");
}
}
Javascript
class Test
{
constructor()
{
console.log("HelloWorld!");
}
}
How to use
Nuget package will be available once I figure out ~how to do docs for api(should be easy) and what to do with esmascript and how to convert to c#.~ NUGET PACKAGE SOON!
- Download a library(Code-Local-Download ZIP)
- Create c# project or use existed one
- Follow this to add reference to project
- In the Main method add:
Assembly assembly = Assembly.GetExecutingAssembly();
CSTOJS cstojs = new(assembly);
cstojs.Generate2Async("FULL PATH TO CSHARP FILE YOU WHAT TO CONVERT");
- Run program and file will be generated in output path(default is "Directory.GetCurrentDirectory()") with name "main.js"(default)
- See below for simple example "HelloWorld"
Example "HelloWorld"
Program.cs
using System.Reflection;
using CSharpToJavaScript;
namespace ConsoleAppTest;
public class Program
{
public static void Main()
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
CSTOJSOptions opt = new()
{
CustomCSNamesToJS = new List<Tuple<string, string>>()
{
new Tuple<string, string>("Console","console"),
new Tuple<string, string>("WriteLine", "log")
},
OutPutFileName = "test.js"
};
CSTOJS cstojs = new(executingAssembly, opt);
cstojs.Generate2Async("C:\\GitReps\\ConsoleAppTest\\CSharp\\test.cs");
}
}
CSharp/test.cs
namespace ConsoleAppTest.CSharp;
public class Test
{
public Test()
{
Console.WriteLine("HelloWorld");
}
}
Above code will generate test.js file that contains:
class Test
{
constructor()
{
console.log("HelloWorld");
}
}
Some Todos
- More comments in code, especially in CSTOJSOptions
- Wiki?
- Better and more examples
- ~Figure out how to do docs for api~ Docs WIP!
Related Repository
https://github.com/TiLied/GenDocsLib
https://github.com/TiLied/GenCSharpLib
Thanks and usings
Microsoft CodeAnalysis CSharp nuget package
MDN-content for js docs
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.CodeAnalysis.CSharp (>= 4.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
First release.