Skip to content

Commit 45b3729

Browse files
committed
Seperate "csharp api to js", needed for GenDocsLib.
Added support for strict inequality.
1 parent 7201ab8 commit 45b3729

File tree

2 files changed

+190
-198
lines changed

2 files changed

+190
-198
lines changed

CSharpToJavaScript/Utils/NETAPI.cs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+

2+
namespace CSharpToJavaScript;
3+
4+
//Currently needs to be in Utils!!
5+
//See GenDocsLib/GenDocs.cs/GenerateDocs
6+
//TODO!!!
7+
8+
internal class NETAPI
9+
{
10+
private readonly TypeName[] _TypeNames = new TypeName[8];
11+
12+
public NETAPI()
13+
{
14+
15+
//
16+
//
17+
//
18+
_TypeNames[0] = new();
19+
_TypeNames[0].Name = nameof(System.Text.Json.JsonSerializer);
20+
_TypeNames[0].JSName = "JSON";
21+
22+
_TypeNames[0].SymbolNames.Add(nameof(System.Text.Json.JsonSerializer.Deserialize), "parse");
23+
_TypeNames[0].SymbolNames.Add(nameof(System.Text.Json.JsonSerializer.Serialize), "stringify");
24+
25+
//
26+
//
27+
//
28+
_TypeNames[1] = new();
29+
_TypeNames[1].Name = nameof(System.Console);
30+
_TypeNames[1].JSName = "console";
31+
32+
_TypeNames[1].SymbolNames.Add(nameof(System.Console.WriteLine), "log");
33+
_TypeNames[1].SymbolNames.Add(nameof(System.Console.Write), "log");
34+
35+
//
36+
//
37+
//
38+
_TypeNames[2] = new();
39+
_TypeNames[2].Name = nameof(System.Collections.Generic.List<object>);
40+
_TypeNames[2].JSName = "Array";
41+
42+
_TypeNames[2].SymbolNames.Add(nameof(System.Collections.Generic.List<object>.Sort), "sort");
43+
_TypeNames[2].SymbolNames.Add(nameof(System.Collections.Generic.List<object>.FindLast), "findLast");
44+
_TypeNames[2].SymbolNames.Add(nameof(System.Collections.Generic.List<object>.Count), "length");
45+
_TypeNames[2].SymbolNames.Add(nameof(System.Collections.Generic.List<object>.Add), "push");
46+
_TypeNames[2].SymbolNames.Add(nameof(System.Collections.Generic.List<object>.Contains), "includes");
47+
48+
//
49+
//
50+
//
51+
_TypeNames[3] = new();
52+
_TypeNames[3].Name = nameof(System.Collections.Generic.Dictionary<object, object>);
53+
_TypeNames[3].JSName = "Map";
54+
55+
_TypeNames[3].SymbolNames.Add(nameof(System.Collections.Generic.Dictionary<object, object>.Keys), "keys()");
56+
_TypeNames[3].SymbolNames.Add(nameof(System.Collections.Generic.Dictionary<object, object>.Values), "values()");
57+
_TypeNames[3].SymbolNames.Add(nameof(System.Collections.Generic.Dictionary<object, object>.ContainsKey), "has");
58+
59+
//
60+
//
61+
//
62+
_TypeNames[4] = new();
63+
_TypeNames[4].Name = nameof(System.String);
64+
_TypeNames[4].JSName = "string";
65+
66+
_TypeNames[4].SymbolNames.Add(nameof(string.Contains), "includes");
67+
_TypeNames[4].SymbolNames.Add(nameof(string.Length), "length");
68+
_TypeNames[4].SymbolNames.Add(nameof(string.Trim), "trim");
69+
_TypeNames[4].SymbolNames.Add(nameof(string.Substring), "substring");
70+
_TypeNames[4].SymbolNames.Add(nameof(string.StartsWith), "startsWith");
71+
_TypeNames[4].SymbolNames.Add(nameof(string.Replace), "replace");
72+
73+
//
74+
//
75+
//
76+
_TypeNames[5] = new();
77+
_TypeNames[5].Name = nameof(System.Threading.Tasks.Task<dynamic>);
78+
_TypeNames[5].JSName = "Promise";
79+
80+
_TypeNames[5].SymbolNames.Add(nameof(System.Threading.Tasks.Task.ContinueWith), "then");
81+
82+
//
83+
//
84+
//
85+
_TypeNames[6] = new();
86+
_TypeNames[6].Name = nameof(System.Array);
87+
_TypeNames[6].JSName = "Array";
88+
89+
_TypeNames[6].SymbolNames.Add(nameof(System.Array.Length), "length");
90+
91+
//
92+
//
93+
//
94+
_TypeNames[7] = new();
95+
_TypeNames[7].Name = nameof(System.Math);
96+
_TypeNames[7].JSName = "Math";
97+
98+
_TypeNames[7].SymbolNames.Add(nameof(System.Math.Sqrt), "sqrt");
99+
_TypeNames[7].SymbolNames.Add(nameof(System.Math.Floor), "floor");
100+
_TypeNames[7].SymbolNames.Add(nameof(System.Math.Exp), "exp");
101+
_TypeNames[7].SymbolNames.Add(nameof(System.Math.Abs), "abs");
102+
_TypeNames[7].SymbolNames.Add(nameof(System.Math.Max), "max");
103+
}
104+
105+
public string? ReturnJSString(string typeName, string? symbolName = null)
106+
{
107+
TypeName? type = null;
108+
109+
for (int i = 0; i < _TypeNames.Length; i++)
110+
{
111+
if (_TypeNames[i].Name == typeName)
112+
{
113+
type = _TypeNames[i];
114+
break;
115+
}
116+
}
117+
118+
if (type != null)
119+
{
120+
if (symbolName == null)
121+
{
122+
return type.JSName;
123+
}
124+
else
125+
{
126+
if (type.SymbolNames.ContainsKey(symbolName))
127+
return type.SymbolNames[symbolName];
128+
else
129+
return null;
130+
}
131+
}
132+
133+
return null;
134+
}
135+
}
136+
137+
internal class TypeName
138+
{
139+
public string Name { get; set; } = string.Empty;
140+
public string JSName { get; set; } = string.Empty;
141+
142+
public System.Collections.Generic.Dictionary<string, string> SymbolNames = new();
143+
144+
public TypeName() { }
145+
}

0 commit comments

Comments
 (0)