CSharpToJavaScript 0.0.9
dotnet add package CSharpToJavaScript --version 0.0.9
NuGet\Install-Package CSharpToJavaScript -Version 0.0.9
<PackageReference Include="CSharpToJavaScript" Version="0.0.9" />
paket add CSharpToJavaScript --version 0.0.9
#r "nuget: CSharpToJavaScript, 0.0.9"
// Install CSharpToJavaScript as a Cake Addin #addin nuget:?package=CSharpToJavaScript&version=0.0.9 // Install CSharpToJavaScript as a Cake Tool #tool nuget:?package=CSharpToJavaScript&version=0.0.9
CSharpToJavaScript
Brute forcing conversion(generating) from C# to Javascript. This is a personal project with the goal of learning and understanding 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)
Nuget package | Website | Try it online! | CLI | VS Code Extension | VS Extension
C# input
namespace ConsoleAppTest.CSharp;
public class Test
{
public Test()
{
Console.WriteLine("HelloWorld!");
}
}
Javascript output
class Test
{
constructor()
{
console.log("HelloWorld!");
}
}
How to use
- 1 Create c# project or use existed one.
- 2 Install nuget package or Download a specific version(visit releases) or Download a master(Code-Local-Download ZIP).
- 3 Skip this if using Nuget package. Follow this to add reference to the project.
- 4 In the Main method add:
CSTOJS cstojs = new();
await cstojs.GenerateOneAsync("FULL PATH TO CSHARP FILE/FOLDER YOU WHAT TO CONVERT");
- 5 Run program and file will be generated in output path(default is "Directory.GetCurrentDirectory()") with name "|CS FILE NAME|.js"(default)
- 6 See below for simple example "HelloWorld"
Example "HelloWorld"
Program.cs
using CSharpToJavaScript;
namespace ConsoleAppTest;
public class Program
{
public static async Task Main()
{
CSTOJS cstojs = new();
await cstojs.GenerateOneAsync("C:\\GitReps\\ConsoleAppTest\\CSharp\\Test.cs");
Console.ReadKey();
}
}
CSharp/Test.cs
using static CSharpToJavaScript.APIs.JS.GlobalObject;
namespace ConsoleAppTest.CSharp;
public class Test
{
public Test()
{
GlobalThis.Console.Log("HelloWorld!");
}
}
Above code will generate "Test.js" file that contains:
class Test
{
constructor()
{
globalThis.console.log("HelloWorld!");
}
}
More examples here. WIP!
Some Todos
- ~More comments in code, especially in CSTOJSOptions~
- Wiki???????
- ~Better and more examples~ Here. WIP!
- ~Figure out how to do docs for api~ Docs WIP!
- ~CLI?~ Here
- ~Visual Studio extension?~ Here
- ~Visual Studio Code extension??? Can I?~ Here
Related Repository
- Library for generating docs: https://github.com/TiLied/GenDocsLib
- Library for generating csharp: https://github.com/TiLied/GenCSharpLib
CLI for library: https://github.com/TiLied/CSTOJS_CLI
VS Code Extension using CLI: https://github.com/TiLied/CSTOJS_VSCode_Ext
VS Extension using CLI: https://github.com/TiLied/CSTOJS_VS_Ext
Website/documentation: https://github.com/TiLied/CSTOJS_Pages
- Blazor WebAssembly: https://github.com/TiLied/CSTOJS_BWA
Thanks for packages and content ❤️
Microsoft CodeAnalysis CSharp nuget package
MDN-content for js docs
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.CodeAnalysis.CSharp (>= 4.12.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- [Hotfix for Blazor WebAssembly.](https://github.com/TiLied/CSharpToJavaScript/commit/f545f208057282efa739122d77f02f9d379bdd73)
For major changelog, see [0.0.08 release](https://github.com/TiLied/CSharpToJavaScript/releases/tag/0.0.08)
**Full Changelog**: https://github.com/TiLied/CSharpToJavaScript/compare/0.0.08...0.0.09