Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: source generated partials when using attributes derived from ValueObjectAttribute<T> #321

Merged
merged 3 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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