Skip to content

Commit cff80cd

Browse files
authored
Update README.md
1 parent e34d33d commit cff80cd

1 file changed

Lines changed: 84 additions & 1 deletion

File tree

README.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,92 @@
11
# CSharpToJavaScript
2-
### Description
32
Brute forcing conversion(translation) from C# to Javascript.
43

4+
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)
5+
56
| C# | Javascript |
67
| --- | --- |
78
| <pre>using static CSharpToJavaScript.APIs.JS.GlobalThis;<br>namespace ConsoleApp1twest.CSharp;<br><br>public class Test<br>{<br> public Test()<br> {<br> Console.Log("HelloWorld!");<br> }<br>}</pre> | <pre>class Test<br>{<br> constructor()<br> {<br> console.log("HelloWorld!");<br> }<br>}</pre>|
89

10+
## How to use
11+
*Nuget package will be available once I figure out how to do docs for api(should be easy) and what to do with esmascript and how to convert to c#.*
12+
13+
- Download a library(Code-Local-Download ZIP)
14+
- Create c# project or use existed one
15+
- Follow [this](https://learn.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio?pivots=dotnet-7-0#add-a-project-reference) to add reference to project
16+
- In the Main method add:
17+
```csharp
18+
Assembly assembly = Assembly.GetExecutingAssembly();
19+
CSTOJS cstojs = new(assembly);
20+
cstojs.Generate2Async("FULL PATH TO CSHARP FILE YOU WHAT TO CONVERT");
21+
```
22+
- Run program and file will be generated in output path(default is "Directory.GetCurrentDirectory()") with name "main.js"(default)
23+
- See below for simple example "HelloWorld"
24+
25+
## Example "HelloWorld"
26+
Program.cs
27+
```csharp
28+
using System.Reflection;
29+
using CSharpToJavaScript;
30+
namespace ProgramTest;
31+
32+
public class Program
33+
{
34+
public static void Main()
35+
{
36+
Assembly executingAssembly = Assembly.GetExecutingAssembly();
37+
CSTOJSOptions opt = new()
38+
{
39+
CustomCSNamesToJS = new List<Tuple<string, string>>()
40+
{
41+
new Tuple<string, string>("Console","console"),
42+
new Tuple<string, string>("WriteLine", "log")
43+
},
44+
OutPutFileName = "test.js"
45+
};
46+
47+
CSTOJS cstojs = new(executingAssembly, opt);
48+
cstojs.Generate2Async("C:\\GitReps\\Program\\Program\\CSharp\\test.cs");
49+
}
50+
51+
}
52+
```
53+
test.cs
54+
```csharp
55+
namespace ProgramTest;
56+
57+
public class Test
58+
{
59+
public Test()
60+
{
61+
Console.WriteLine("HelloWorld");
62+
}
63+
64+
}
65+
```
66+
Above code will generate test.js file that contains:
67+
```javascript
68+
class Test
69+
{
70+
constructor()
71+
{
72+
console.log("HelloWorld");
73+
}
74+
}
75+
```
76+
## Some Todos
77+
- [ ] More comments in code, especially in [CSTOJSOptions](https://github.com/TiLied/CSharpToJavaScript/blob/master/CSharpToJavaScript/CSTOJSOptions.cs)
78+
- [ ] Wiki?
79+
- [ ] Better and more examples
80+
- [ ] Figure out how to do docs for [api](https://github.com/TiLied/CSharpToJavaScript/tree/master/CSharpToJavaScript/APIs/JS)
81+
82+
## Related Repository
83+
https://github.com/TiLied/GenDocsLib
84+
85+
https://github.com/TiLied/GenCSharpLib
86+
87+
## Thanks and usings
88+
[Microsoft CodeAnalysis CSharp](https://www.nuget.org/packages/Microsoft.CodeAnalysis.CSharp/) nuget package
89+
90+
[MDN-content](https://github.com/mdn/content) for docs
91+
992

0 commit comments

Comments
 (0)