|
15 | 15 | namespace SourceGenerator; |
16 | 16 |
|
17 | 17 | static class Extensions { |
18 | | - public static IEnumerable<ClassDeclarationSyntax> FindClasses(this Compilation compilation, Func<ClassDeclarationSyntax, bool> predicate) |
19 | | - => compilation.SyntaxTrees |
20 | | - .Select(tree => compilation.GetSemanticModel(tree)) |
21 | | - .SelectMany(model => model.SyntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>()) |
22 | | - .Where(predicate); |
| 18 | + extension(Compilation compilation) { |
| 19 | + public IEnumerable<ClassDeclarationSyntax> FindClasses(Func<ClassDeclarationSyntax, bool> predicate) |
| 20 | + => compilation.SyntaxTrees |
| 21 | + .Select(tree => compilation.GetSemanticModel(tree)) |
| 22 | + .SelectMany(model => model.SyntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>()) |
| 23 | + .Where(predicate); |
23 | 24 |
|
24 | | - public static IEnumerable<ClassDeclarationSyntax> FindAnnotatedClasses(this Compilation compilation, string attributeName, bool strict) { |
25 | | - return compilation.FindClasses( |
26 | | - syntax => syntax.AttributeLists.Any(list => list.Attributes.Any(CheckAttribute)) |
27 | | - ); |
| 25 | + public IEnumerable<ClassDeclarationSyntax> FindAnnotatedClasses(string attributeName, bool strict) { |
| 26 | + return compilation.FindClasses( |
| 27 | + syntax => syntax.AttributeLists.Any(list => list.Attributes.Any(CheckAttribute)) |
| 28 | + ); |
28 | 29 |
|
29 | | - bool CheckAttribute(AttributeSyntax attr) { |
30 | | - var name = attr.Name.ToString(); |
31 | | - return strict ? name == attributeName : name.StartsWith(attributeName); |
| 30 | + bool CheckAttribute(AttributeSyntax attr) { |
| 31 | + var name = attr.Name.ToString(); |
| 32 | + return strict ? name == attributeName : name.StartsWith(attributeName); |
| 33 | + } |
32 | 34 | } |
33 | 35 | } |
34 | 36 |
|
|
0 commit comments