Reputation: 16959
Using Roslyn I am getting the public methods like this:
var semanticModel = file.GetSemanticModelAsync().Result;
var classParser = new ClassParser(semanticModel);
var tree = file.GetSyntaxTreeAsync().Result;
var methodDeclarations = tree.GetRoot().DescendantNodes()
.OfType<MethodDeclarationSyntax>()
.Where(method => method.Modifiers.Any(modifier => modifier.Kind() == SyntaxKind.PublicKeyword)).ToList();
how is it possible to get the assembly name from the MethodDeclarationSyntax object?
Upvotes: 1
Views: 275
Reputation: 15197
Since you already have the semantic model, you can query it for symbols. The symbols have references to the information about the assembly they are contained in:
foreach (MethodDeclarationSyntax method in methodDeclarations)
{
var symbol = semanticModel.GetEnclosingSymbol(method.SpanStart);
var assembly = symbol.ContainingAssembly;
var assemblyName = assembly.Identity.Name;
}
Upvotes: 2