|
1 | 1 | using System.Reflection; |
| 2 | +using System.Resources; |
| 3 | +using System.Runtime.Versioning; |
2 | 4 |
|
3 | 5 | using Microsoft.CodeAnalysis; |
4 | 6 | using Microsoft.CodeAnalysis.CSharp.Syntax; |
5 | | -using Microsoft.CodeAnalysis.CSharp; |
6 | 7 |
|
7 | 8 | namespace AssemblyMetadata.Generators; |
8 | 9 |
|
9 | 10 | [Generator(LanguageNames.CSharp)] |
10 | 11 | public class AssemblyMetadataGenerator : IIncrementalGenerator |
11 | 12 | { |
| 13 | + private static readonly HashSet<string> _attributes = new() |
| 14 | + { |
| 15 | + nameof(AssemblyCompanyAttribute), |
| 16 | + nameof(AssemblyConfigurationAttribute), |
| 17 | + nameof(AssemblyCopyrightAttribute), |
| 18 | + nameof(AssemblyCultureAttribute), |
| 19 | + nameof(AssemblyDelaySignAttribute), |
| 20 | + nameof(AssemblyDescriptionAttribute), |
| 21 | + nameof(AssemblyFileVersionAttribute), |
| 22 | + nameof(AssemblyInformationalVersionAttribute), |
| 23 | + nameof(AssemblyKeyFileAttribute), |
| 24 | + nameof(AssemblyKeyNameAttribute), |
| 25 | + nameof(AssemblyMetadataAttribute), |
| 26 | + nameof(AssemblyProductAttribute), |
| 27 | + nameof(AssemblySignatureKeyAttribute), |
| 28 | + nameof(AssemblyTitleAttribute), |
| 29 | + nameof(AssemblyTrademarkAttribute), |
| 30 | + nameof(AssemblyVersionAttribute), |
| 31 | + nameof(NeutralResourcesLanguageAttribute), |
| 32 | + nameof(TargetFrameworkAttribute), |
| 33 | + }; |
| 34 | + |
12 | 35 | public void Initialize(IncrementalGeneratorInitializationContext context) |
13 | 36 | { |
14 | 37 | var provider = context.SyntaxProvider |
@@ -46,7 +69,7 @@ private static GeneratorContext SemanticTransform(GeneratorAttributeSyntaxContex |
46 | 69 | foreach (var attribute in attributes) |
47 | 70 | { |
48 | 71 | var name = attribute.AttributeClass?.Name; |
49 | | - if (name == null) |
| 72 | + if (name == null || !_attributes.Contains(name)) |
50 | 73 | continue; |
51 | 74 |
|
52 | 75 | if (attribute.ConstructorArguments.Length == 1) |
|
0 commit comments