CSharpToJavaScript 0.0.2

Additional Details

Use .Net 8 version(0.0.06+).
.Net 7 versions will soon be unlisted.

There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package CSharpToJavaScript --version 0.0.2
                    
NuGet\Install-Package CSharpToJavaScript -Version 0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CSharpToJavaScript" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharpToJavaScript" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="CSharpToJavaScript" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CSharpToJavaScript --version 0.0.2
                    
#r "nuget: CSharpToJavaScript, 0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CSharpToJavaScript@0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSharpToJavaScript&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=CSharpToJavaScript&version=0.0.2
                    
Install as a Cake Tool

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)

Nuget package

C#

using static CSharpToJavaScript.APIs.JS.GlobalObject.GlobalThis;
namespace ConsoleAppTest.CSharp;

public class Test							
{
	public Test()
	{
		Console.Log("HelloWorld!");
	}
}

Javascript

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:
Assembly assembly = Assembly.GetExecutingAssembly();
CSTOJS cstojs = new(assembly);
await cstojs.GenerateAsync("FULL PATH TO CSHARP FILE YOU WHAT TO CONVERT");
  • 5 Run program and file will be generated in output path(default is "Directory.GetCurrentDirectory()") with name "main.js"(default)
  • 6 See below for simple example "HelloWorld"

Example "HelloWorld"

Program.cs

using System.Reflection;
using CSharpToJavaScript;
namespace ConsoleAppTest;

public class Program
{
	public static async Task Main()
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		CSTOJS cstojs = new(executingAssembly);
		await cstojs.GenerateAsync("C:\\GitReps\\ConsoleAppTest\\CSharp\\Test.cs");

		Console.ReadKey();
	}
}

CSharp/test.cs

using static CSharpToJavaScript.APIs.JS.GlobalObject.GlobalThis;
namespace ConsoleAppTest.CSharp;

public class Test
{
	public Test()
	{
		Console.Log("HelloWorld");
	}
}

Above code will generate test.js file that contains:

class Test
{
	constructor()
 	{
   		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!

https://github.com/TiLied/GenDocsLib

https://github.com/TiLied/GenCSharpLib

Thanks and usings

Microsoft CodeAnalysis CSharp nuget package

MDN-content for js docs

Product 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.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.3 180 12/15/2025
0.1.2 422 12/8/2025
0.1.1 192 11/24/2025
0.1.0 128 9/27/2025
0.0.10 268 9/15/2025

**Breaking changes!**

**"GlobalThis" now in "GlobalObject".
Renamed method from "Generate2Async" to "GenerateAsync".**

- Updated generated csharp and xml documents.
- Added more comments to code,
- Initial support for built-it types/generics.
- Many missing tokens.
- Support for `while` loop.
- `foreach` to `for..of`.
- `$"{test}"` to ```` `${test}` ````.
- Bug fixes.

**Full Changelog**: https://github.com/TiLied/CSharpToJavaScript/compare/0.0.01...0.0.02