4

Is there a way to find out whether class is partial inside Roslyn analyzer? There is a PartialImplementationPart in IMethodSymbol, but nothing similar for INamedTypeSymbol.

I'm writing a Source Generator, and I want to generate second part of the class only if it's possible (if first part is partial).

maxc137
  • 2,291
  • 3
  • 20
  • 32

2 Answers2

10

You could use the Modifier List to check if the class is partial.

var isPartial = classDeclaration.Modifiers
                                .Any(m => m.IsKind(SyntaxKind.PartialKeyword));
Anu Viswan
  • 17,797
  • 2
  • 22
  • 51
0

You can also look at ISymbol.Locations if you only have access to the ISymbol - more than one location is a pretty good indicator that it's a partial class.

Matt Whitfield
  • 6,436
  • 3
  • 29
  • 44