66using Microsoft . CodeAnalysis . CSharp ;
77using System . Threading . Tasks ;
88using Microsoft . CodeAnalysis ;
9+ using CSharpToJavaScript . Utils ;
10+ using System ;
911
1012namespace 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}
0 commit comments