Skip to content

Commit

Permalink
Fix issue when attribute has no constructor arguments
Browse files Browse the repository at this point in the history
The generator is called even if the syntax tree is partially valid, such as when the constructor arguments for an assembly-level attribute is still not complete. In those cases, we'd fail and the generator would get disabled.

Fixes #77
  • Loading branch information
kzu committed Oct 21, 2021
1 parent b83a3df commit a66c0c4
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/ThisAssembly.AssemblyInfo/AssemblyInfoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void Execute(GeneratorExecutionContext context)

var metadata = context.Compilation.Assembly.GetAttributes()
.Where(x => !string.IsNullOrEmpty(x.AttributeClass?.Name) && attributes.Contains(x.AttributeClass!.Name))
.Where(x => x.ConstructorArguments.Length == 1)
.Select(x => new KeyValuePair<string, string?>(x.AttributeClass!.Name.Substring(8).Replace("Attribute", ""), (string?)x.ConstructorArguments[0].Value))
.ToDictionary(x => x.Key, x => x.Value ?? "");

Expand Down

0 comments on commit a66c0c4

Please sign in to comment.