GithubHelp home page GithubHelp logo

rchcomm / csharptojavascript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tilied/csharptojavascript

0.0 0.0 0.0 21.73 MB

Brute forcing conversion(generating) from C# to Javascript. Using roslyn api.

Home Page: https://tilied.github.io/CSTOJS_Pages/

License: MIT License

C# 100.00%

csharptojavascript's Introduction

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#

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/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

Related Repository

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 <3

Microsoft CodeAnalysis CSharp nuget package

MDN-content for js docs

csharptojavascript's People

Contributors

tilied avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.