CSharpToJavaScript 0.0.8
See the version list below for details.
dotnet add package CSharpToJavaScript --version 0.0.8
NuGet\Install-Package CSharpToJavaScript -Version 0.0.8
<PackageReference Include="CSharpToJavaScript" Version="0.0.8" />
paket add CSharpToJavaScript --version 0.0.8
#r "nuget: CSharpToJavaScript, 0.0.8"
// Install CSharpToJavaScript as a Cake Addin #addin nuget:?package=CSharpToJavaScript&version=0.0.8 // Install CSharpToJavaScript as a Cake Tool #tool nuget:?package=CSharpToJavaScript&version=0.0.8
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.
**Highlight:**
Method "GenerateOneContinuously" continuously watching for file modifications:

_Options used: UseStrictEquality, KeepBraceOnTheSameLine, NormalizeWhitespace_
**Rest of changes:**
- [NullableType is ignored for properties.](https://github.com/TiLied/CSharpToJavaScript/commit/1f03468fa95e96d468248582fbd3091459c32e59)
- - Added a console warning if the object initializer is used.
- - Better output c# lines into js when debug is enabled.
- - Clean up.
- [Added support for property default values.](https://github.com/TiLied/CSharpToJavaScript/commit/613a1f94c11b64f67062e256526323aa65790e77)
- - Updated Microsoft.CodeAnalysis.CSharp to 4.10.0.
- [Fixed static properties.](https://github.com/TiLied/CSharpToJavaScript/commit/27afa95a97656ea56c38ce7bc80e0725e74b83f8)
- - Ignore ArrayType in parameters.
- - Small changes to code.
- [Added missing arithmetic expressions and tokens.](https://github.com/TiLied/CSharpToJavaScript/commit/db2c5c8aee8f0e4173da9cdd0573ca16d97961eb)
- [Added method "GenerateOneContinuously":](https://github.com/TiLied/CSharpToJavaScript/commit/d646dcf4a1b55051ed4ceedea7ad1fdd6df4017a)
generating continuously by watching the cs file.
- - Added option " UseStrictEquality":
replace '<c>==</c>' with '<c>===</c>' default false.
- - Initial support dictionary to map.
- - Small changes, bug fixes.
- [Small changes, mostly renames.](https://github.com/TiLied/CSharpToJavaScript/commit/d8068f58adadd8ddee566dee49f370aeb44309a1)
- [Update License.](https://github.com/TiLied/CSharpToJavaScript/commit/413f56fb0ea283a073f3f87bfc456a07af8f2c80)
- [Added BigInt.](https://github.com/TiLied/CSharpToJavaScript/commit/f2d3732df4953d0243ffa8269e0f9530ca0ccc58)
- [Added Error objects.](https://github.com/TiLied/CSharpToJavaScript/commit/bebe33719742aa5049f69fa03cf9afb17dd16ee4)
- [Uncomment some piece of code in GlobalObject.](https://github.com/TiLied/CSharpToJavaScript/commit/ad00098d96a61a0073aaac41ade5ea4beec285d3)
- [Added missing GM api alongside documentation.](https://github.com/TiLied/CSharpToJavaScript/commit/272a57a96ee48f1660183a56c54625b125814ae8)
- [Added EnumValue attribute.](https://github.com/TiLied/CSharpToJavaScript/commit/e61ff7ab174d9958a3f4b91a18d62a50309a731f)
- [Updated nuget "Microsoft.CodeAnalysis.CSharp" to 4.12.0](https://github.com/TiLied/CSharpToJavaScript/commit/417e521093005167be64a31b4efbcc0f4b8b1a53)
- [Removed mostly whitespaces when used with "KeepBraceOnTheSameLine".](https://github.com/TiLied/CSharpToJavaScript/commit/3a8bdf6c09f229bbae626c22084a909571ee5680)
Still, I recommend using "KeepBraceOnTheSameLine" with the "NormalizeWhitespace" option.
- - Fixed bug where file generates simultaneously.
- [Added ValueAttribute and EnumValueAttribute.](https://github.com/TiLied/CSharpToJavaScript/commit/7201ab8c90700d334e1f6dfc4c97b4844cb2a3f9)
- [Separate "csharp api to js", needed for GenDocsLib.](https://github.com/TiLied/CSharpToJavaScript/commit/45b372917393157843ac613e0cbe685bca794025)
- - Added support for strict inequality.
- [Updated comment with strict inequality.](https://github.com/TiLied/CSharpToJavaScript/commit/5a92d56a41c234ef5ebc214f3c2ecaee1358eac3)
- [Added log when using GenerateOneContinuously.](https://github.com/TiLied/CSharpToJavaScript/commit/c462bf226ad0c637e9d0aa6fd6ad4e172bfb145c)
- [Updated generated docs.](https://github.com/TiLied/CSharpToJavaScript/commit/76307cd013129b7a8d626e8b6899950f05f5d2b8)
- [Corrected namespace.](https://github.com/TiLied/CSharpToJavaScript/commit/6499c72a9f476018dd6b32b91ffda41e012a183e)
- [Renamed option AddSBInFront to AddSBAtTheTop.](https://github.com/TiLied/CSharpToJavaScript/commit/7bef6ad4506a57bce180b7141b446aa6385b0ce5)
- - Renamed option AddSBInEnd to AddSBAtTheBottom.
- [Updated generated docs.](https://github.com/TiLied/CSharpToJavaScript/commit/911a50a3e3a75fb53b4a77318d3c618c26fea661)
See GenDocsLib.
- [Updated generated c#.](https://github.com/TiLied/CSharpToJavaScript/commit/39dcf26a05306b55f3a531d28d38eecba9c6aafa)
See GenCSharpLib.
- [Updated generated c#.](https://github.com/TiLied/CSharpToJavaScript/commit/dac7efcd17907e880812bf15c83718efd4df28e8)
- [Moved checking attributes to a separate method.](https://github.com/TiLied/CSharpToJavaScript/commit/aa1c739261642f7d984f4aa3689f477f118464a4)
- [Added expressions.](https://github.com/TiLied/CSharpToJavaScript/commit/1ec3f4e5fb269648ee529b0eec6329200db9867d)
**Full Changelog**: https://github.com/TiLied/CSharpToJavaScript/compare/0.0.07...0.0.08