CSharpToJavaScript 0.0.6

dotnet add package CSharpToJavaScript --version 0.0.6
NuGet\Install-Package CSharpToJavaScript -Version 0.0.6
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.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CSharpToJavaScript --version 0.0.6
#r "nuget: CSharpToJavaScript, 0.0.6"
#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.
// Install CSharpToJavaScript as a Cake Addin
#addin nuget:?package=CSharpToJavaScript&version=0.0.6

// Install CSharpToJavaScript as a Cake Tool
#tool nuget:?package=CSharpToJavaScript&version=0.0.6

CSharpToJavaScript

Brute forcing conversion(generating) 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 | Website | Try it online! | CLI | VS Code Extension | VS Extension

C#

namespace ConsoleAppTest.CSharp;

public class Test							
{
	public Test()
	{
		Console.WriteLine("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:
CSTOJS cstojs = new();
await cstojs.GenerateOneAsync("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 "|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

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

Thanks for packages and content ❤️

Microsoft CodeAnalysis CSharp nuget package

MDN-content for js docs

Product 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. 
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.0.6 202 12/6/2023
0.0.5 128 9/27/2023
0.0.4 110 9/20/2023
0.0.3 109 9/14/2023
0.0.2 146 7/16/2023
0.0.1 147 7/6/2023

- [Added "LessThanEqualsToken".](https://github.com/TiLied/CSharpToJavaScript/commit/2f845c674b10e40d3878f4d70a041cecad9a38f7)
- - Small changes to comments/code.
- [Added Number object.](https://github.com/TiLied/CSharpToJavaScript/commit/dee9e0380c33a2cbdf5aee0b0ff0c93be60f667e)
- - Further improvement to this.
- - Small clean-up.
- [.Net 8](https://github.com/TiLied/CSharpToJavaScript/commit/76def38d71fbe183e01f90db436904ddb6206aa0)
- - Updated generated csharp code(Many missing webapi from w3c).
- - Added method "GenerateOne" returns list of StringBuilders.
- - Added method "GenerateOneFromStringAsync" writes a file, return empty Task.
- - Added "System.Console" and "CSharpToJavaScript" references as default.
- - c# const -> js const.
- - c# static constructor -> js static constructor.
- - private js fields for c# auto-implemented properties.
- - c# static -> js static
- - Better "this.".
- - Small changes and fixes.
- [Small changes to static and "this".](https://github.com/TiLied/CSharpToJavaScript/commit/2576a202a603414c5301b2ce090c39ba5142d3b1)
- [Updated Microsoft.CodeAnalysis.CSharp to 4.8.0](https://github.com/TiLied/CSharpToJavaScript/commit/b3b93e1535bd60108c75033027c18f346da4b9ae)
- - Updated generated csharp and xml docs.
- [Added "Properties of the Global Object" into "GlobalThis".](https://github.com/TiLied/CSharpToJavaScript/commit/f7039c206a43f6f87865bbbddadc9176a049de48)

**Full Changelog**: https://github.com/TiLied/CSharpToJavaScript/compare/0.0.05...0.0.06