-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
36 lines (30 loc) · 1.21 KB
/
Program.cs
File metadata and controls
36 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using static System.Console;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.IO;
using StandAloneCSharpParser.model;
namespace StandAloneCSharpParser
{
class Program
{
static void Main(string[] args)
{
string programPath = @"/home/borisz/Desktop/Labor/Standalone/files2parse/CentroidBasedClustering.cs";
string programText = File.ReadAllText(programPath);
SyntaxTree tree = CSharpSyntaxTree.ParseText(programText);
CompilationUnitSyntax root = tree.GetCompilationUnitRoot();
CSharpCompilation compilation = CSharpCompilation.Create("CSharpCompilation")
.AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
.AddSyntaxTrees(tree);
SemanticModel model = compilation.GetSemanticModel(tree);
CsharpDbContext dbContext = new CsharpDbContext();
dbContext.Database.EnsureCreated();
var visitor = new AstVisitor(dbContext, model, tree);
visitor.Visit(root);
dbContext.SaveChanges();
}
}
}