0

I am trying to find the path of the base class via Roslyn but I could not find any helpful resource. Does anyone have an idea how to approach the problem.

E.g. path: "../File1.cs" contains:

using ...;

namespace Extraction
{


 class Class1 : Class2 {
    
    }
}

Assuming that Class2 is in path: "../../File2.cs", I want to analyze the ".../File1.cs" file and find the base class (Class2) path using Roslyn. Is it possible?

Edit: What I would like to achieve is merging all the methods of the derived class and parent classes (up to the last level) into one class. I was thinking to initially find the paths of all parent classes (iteratively) and afterwards merge them into one class.

ce8
  • 23
  • 1
  • 3
  • I'd implement an source generator, create an `Attribute` i'd look for with a `SyntaxReceiver` or `SyntaxContextReceiver`, use the semantic model to get `SymbolInfo` of the `MemberDeclarationSyntax` the attribute is applied to and query the `SymbolInfo` for parents and declarations etc. – Patrick Beynio May 09 '22 at 19:40
  • otherwise I'd use `MSBuildWorkspace` to load a project, get its `Compilation` and than ask the compilation for info of symbol with name of `Class1` and then basically do the same – Patrick Beynio May 09 '22 at 19:45
  • @PatrickBeynio, any idea how much does the usage of MSBuildWorkspace affect the performance comparing with Syntax Analyzer? – ce8 May 28 '22 at 12:37

0 Answers0