Skip to content

Commit

Permalink
Update AssemblyMetadataGenerator.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Aug 11, 2023
1 parent e1fc354 commit ee971b3
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/AssemblyMetadata.Generators/AssemblyMetadataGenerator.cs
Original file line number Diff line number Diff line change
@@ -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<string> _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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee971b3

Please sign in to comment.