Skip to content

Commit 5a676e6

Browse files
committed
Small clean up in CSTOJS.cs
1 parent 209e22c commit 5a676e6

File tree

2 files changed

+10
-28
lines changed

2 files changed

+10
-28
lines changed

CSharpToJavaScript/CSTOJS.cs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Microsoft.CodeAnalysis.CSharp;
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis;
9+
using CSharpToJavaScript.Utils;
10+
using System;
911

1012
namespace CSharpToJavaScript
1113
{
@@ -57,56 +59,35 @@ public async Task Generate2Async(string path)
5759
{
5860
string fileCS = await File.ReadAllTextAsync(path);
5961

60-
Microsoft.CodeAnalysis.SyntaxTree tree = CSharpSyntaxTree.ParseText(fileCS);
62+
SyntaxTree tree = CSharpSyntaxTree.ParseText(fileCS);
6163
CompilationUnitSyntax root = tree.GetCompilationUnitRoot();
6264

63-
//Walker walker = new();
6465
string assemblyPath = Path.GetDirectoryName(_Assembly.Location);
65-
List<MetadataReference> references = new()
66-
{
67-
//MetadataReference.CreateFromFile(_Assembly.Location),
68-
//MetadataReference.CreateFromFile(typeof(CSTOJS).Assembly.Location)
69-
//MetadataReference.CreateFromFile(Path.Combine(assemblyPath, "System.Private.CoreLib.dll"))
70-
};
66+
List<MetadataReference> references = new() { };
7167

7268
string rtPath = Path.GetDirectoryName(typeof(object).Assembly.Location);
73-
//references.Add(MetadataReference.CreateFromFile(Path.Combine(rtPath, "System.dll")));
69+
7470
references.Add(MetadataReference.CreateFromFile(Path.Combine(rtPath, "System.Private.CoreLib.dll")));
7571

7672
var a = _Assembly.GetReferencedAssemblies();
7773
foreach (var item in a)
7874
{
7975
if (File.Exists(Path.Combine(assemblyPath, item.Name + ".dll")))
8076
references.Add(MetadataReference.CreateFromFile(Path.Combine(assemblyPath, item.Name + ".dll")));
81-
else
77+
else
8278
{
8379
if (File.Exists(Path.Combine(rtPath, item.Name + ".dll")))
8480
references.Add(MetadataReference.CreateFromFile(Path.Combine(rtPath, item.Name + ".dll")));
8581
}
8682
}
87-
/*
88-
var sss = root.DescendantNodes()
89-
.OfType<BinaryExpressionSyntax>()
90-
.Single();*/
91-
//https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/get-started/semantic-analysis
92-
//CSharpCompilation compilation = CSharpCompilation.Create("HelloWorld"),
93-
// references: references.ToArray(),
94-
// options: new CSharpCompilationOptions(OutputKind.ConsoleApplication))
83+
9584
CSharpCompilation compilation = CSharpCompilation
9685
.Create("HelloWorld")
9786
.AddReferences(references.ToArray())
9887
.AddSyntaxTrees(root.SyntaxTree);
9988

10089
Model = compilation.GetSemanticModel(root.SyntaxTree);
10190

102-
// Use the syntax tree to find "using System;"
103-
UsingDirectiveSyntax usingSystem = root.Usings[0];
104-
NameSyntax systemName = usingSystem.Name;
105-
106-
// Use the semantic model for symbol information:
107-
SymbolInfo nameInfo = Model.GetSymbolInfo(systemName);
108-
var systemSymbol = (INamespaceSymbol)nameInfo.Symbol;
109-
11091
_Walker.JSSB.Append(_Options.AddSBInFront);
11192

11293
_Walker.Visit(root);
@@ -119,6 +100,7 @@ public async Task Generate2Async(string path)
119100
}
120101

121102
await File.WriteAllTextAsync(Path.Combine(_Options.OutPutPath, _Options.OutPutFileName), _Walker.JSSB.ToString());
103+
SM.Log($"path: {_Options.OutPutPath} file: {_Options.OutPutFileName}");
122104
}
123105
}
124106
}

CSharpToJavaScript/CSharpToJavaScript.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<VersionPrefix>0.0.01</VersionPrefix>
55

66
<TargetFramework>net7.0</TargetFramework>
77
<ImplicitUsings>disable</ImplicitUsings>
88
<Nullable>enable</Nullable>
9-
<GenerateDocumentationFile>False</GenerateDocumentationFile>
9+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
1010
<Authors>TiLied</Authors>
1111
<Description>Brute forcing conversion(translation) from C# to Javascript.</Description>
1212
<PackageProjectUrl>https://tilied.github.io/CSharpToJavaScript/</PackageProjectUrl>

0 commit comments

Comments
 (0)