From ee971b3325221bcb7f77b0004463d9b2be223b79 Mon Sep 17 00:00:00 2001 From: Paul Welter Date: Fri, 11 Aug 2023 09:06:31 -0500 Subject: [PATCH] Update AssemblyMetadataGenerator.cs --- .../AssemblyMetadataGenerator.cs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/AssemblyMetadata.Generators/AssemblyMetadataGenerator.cs b/src/AssemblyMetadata.Generators/AssemblyMetadataGenerator.cs index 2393f94..c38025a 100644 --- a/src/AssemblyMetadata.Generators/AssemblyMetadataGenerator.cs +++ b/src/AssemblyMetadata.Generators/AssemblyMetadataGenerator.cs @@ -1,14 +1,37 @@ using System.Reflection; +using System.Resources; +using System.Runtime.Versioning; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.CSharp; namespace AssemblyMetadata.Generators; [Generator(LanguageNames.CSharp)] public class AssemblyMetadataGenerator : IIncrementalGenerator { + private static readonly HashSet _attributes = new() + { + nameof(AssemblyCompanyAttribute), + nameof(AssemblyConfigurationAttribute), + nameof(AssemblyCopyrightAttribute), + nameof(AssemblyCultureAttribute), + nameof(AssemblyDelaySignAttribute), + nameof(AssemblyDescriptionAttribute), + nameof(AssemblyFileVersionAttribute), + nameof(AssemblyInformationalVersionAttribute), + nameof(AssemblyKeyFileAttribute), + nameof(AssemblyKeyNameAttribute), + nameof(AssemblyMetadataAttribute), + nameof(AssemblyProductAttribute), + nameof(AssemblySignatureKeyAttribute), + nameof(AssemblyTitleAttribute), + nameof(AssemblyTrademarkAttribute), + nameof(AssemblyVersionAttribute), + nameof(NeutralResourcesLanguageAttribute), + nameof(TargetFrameworkAttribute), + }; + public void Initialize(IncrementalGeneratorInitializationContext context) { var provider = context.SyntaxProvider @@ -46,7 +69,7 @@ private static GeneratorContext SemanticTransform(GeneratorAttributeSyntaxContex foreach (var attribute in attributes) { var name = attribute.AttributeClass?.Name; - if (name == null) + if (name == null || !_attributes.Contains(name)) continue; if (attribute.ConstructorArguments.Length == 1)