| Name | Message | Date |
|---|---|---|
| 📄 Poc.csproj | 1 day ago | |
| 📄 Program.cs | 1 day ago |
📄
Program.cs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System; using System.Linq; using System.Reflection; using Microsoft.Build.Locator; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.MSBuild; MSBuildLocator.RegisterDefaults(); using var workspace = MSBuildWorkspace.Create(); var solution = await workspace.OpenSolutionAsync(@"..\Reacher.slnx"); var project = solution.Projects.First(p => p.AssemblyName == Assembly.GetExecutingAssembly().GetName().Name); var compilation = await project.GetCompilationAsync(); if (compilation is null) { Console.WriteLine($"Cannot get compilation for {project.Name}"); return; } var entryPoint = compilation.GetEntryPoint(default); if (entryPoint is null) { Console.WriteLine($"No entry point in {project.Name}"); return; #pragma warning disable CS0162 // Intentional to test reachability Console.WriteLine($"No entry point in {project.Name}"); #pragma warning restore CS0162 } foreach (var declaration in entryPoint.DeclaringSyntaxReferences) { Console.WriteLine($"Entry point was declared at {declaration.SyntaxTree.GetLineSpan(declaration.Span)}"); var semanticModel = compilation.GetSemanticModel(declaration.SyntaxTree, ignoreAccessibility: true); var statements = declaration.GetSyntax().DescendantNodes().OfType<StatementSyntax>(); foreach (var statement in statements) { var controlFlowAnalysis = semanticModel.AnalyzeControlFlow(statement); Console.WriteLine( $"Is {statement.Kind()} at {declaration.SyntaxTree.GetLineSpan(statement.Span)} reachable: {controlFlowAnalysis?.StartPointIsReachable}" ); if (false && true) { #pragma warning disable CS0162 // Intentional to test reachability Console.WriteLine("Hello"); #pragma warning restore CS0162 } } }