从MethodDeclarationSyntax对象中获取程序集名称可以通过以下步骤实现:
SyntaxTree syntaxTree = methodDeclarationSyntax.SyntaxTree;
CompilationUnitSyntax root = syntaxTree.GetRoot() as CompilationUnitSyntax;
NamespaceDeclarationSyntax namespaceDeclaration = root.Members.OfType<NamespaceDeclarationSyntax>()
.FirstOrDefault();
ClassDeclarationSyntax classDeclaration = namespaceDeclaration.Members.OfType<ClassDeclarationSyntax>()
.FirstOrDefault();
string filePath = syntaxTree.FilePath;
Assembly assembly = Assembly.LoadFrom(filePath);
string assemblyName = assembly.GetName().Name;
综上所述,以上步骤可以从MethodDeclarationSyntax对象中获取程序集名称。
领取专属 10元无门槛券
手把手带您无忧上云