Skip to content

Commit

Permalink
Merge pull request #321 from jammehcow/fix/319-derived-generic-attrib…
Browse files Browse the repository at this point in the history
…utes

fix: source generated partials when using attributes derived from ValueObjectAttribute<T>
  • Loading branch information
SteveDunn committed Jan 14, 2023
2 parents 2b62a1d + b4e0909 commit 6b9328e
Show file tree
Hide file tree
Showing 3 changed files with 430 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/Vogen/VoFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ internal static class VoFilter
public static IEnumerable<AttributeData> TryGetValueObjectAttributes(INamedTypeSymbol voSymbolInformation)
{
var attrs = voSymbolInformation.GetAttributes();

return attrs.Where(
a => a.AttributeClass?.FullName() == "Vogen.ValueObjectAttribute"
|| a.AttributeClass?.BaseType?.FullName() == "Vogen.ValueObjectAttribute");
a => a.AttributeClass?.FullName() == "Vogen.ValueObjectAttribute"
|| a.AttributeClass?.BaseType?.FullName() == "Vogen.ValueObjectAttribute"
|| a.AttributeClass?.BaseType?.BaseType?.FullName() == "Vogen.ValueObjectAttribute");
}

// This is stage 2 in the pipeline - we filter down to just 1 target
Expand All @@ -34,16 +35,16 @@ public static IEnumerable<AttributeData> TryGetValueObjectAttributes(INamedTypeS
var voSyntaxInformation = (TypeDeclarationSyntax) context.Node;

var semanticModel = context.SemanticModel;

var voSymbolInformation = (INamedTypeSymbol) semanticModel.GetDeclaredSymbol(context.Node)!;

var attributeData = TryGetValueObjectAttributes(voSymbolInformation).ToImmutableArray();

if(attributeData.Length > 0)
{
return new VoTarget(
semanticModel,
voSyntaxInformation,
voSyntaxInformation,
semanticModel.GetDeclaredSymbol(context.Node)!.ContainingType,
voSymbolInformation,
attributeData);
Expand Down Expand Up @@ -71,4 +72,4 @@ public static bool IsTarget(INamedTypeSymbol? voClass)

return voAttribute is not null;
}
}
}
24 changes: 23 additions & 1 deletion tests/SnapshotTests/GenericAttributeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Shared;
using VerifyXunit;
using Vogen;
Expand Down Expand Up @@ -57,6 +57,28 @@ public partial struct CustomerId
");
}

[SkippableFact]
public Task Produces_instances_with_derived_attribute()
{
return RunTest(@"using Vogen;
namespace Whatever;
public class CustomGenericAttribute : ValueObjectAttribute<int> {
}
[CustomGenericAttribute]
[Instance(name: ""Unspecified"", value: -1, tripleSlashComment: ""a short description that'll show up in intellisense"")]
[Instance(name: ""Unspecified1"", value: -2)]
[Instance(name: ""Unspecified2"", value: -3, tripleSlashComment: ""<some_xml>whatever</some_xml"")]
[Instance(name: ""Unspecified3"", value: -4)]
[Instance(name: ""Cust42"", value: 42)]
public partial struct CustomerId
{
}
");
}

[SkippableFact]
public Task Validation_with_PascalCased_validate_method()
{
Expand Down
Loading

0 comments on commit 6b9328e

Please sign in to comment.