Skip to content

Commit 2712676

Browse files
committed
Fix record resolution and update tests
1 parent d7ad03c commit 2712676

5 files changed

+12
-641
lines changed

src/Validation/gen/Parsers/ValidationsGenerator.TypesParser.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb
131131
// Process all parameters in constructor order to maintain parameter ordering
132132
foreach (var parameter in primaryConstructor.Parameters)
133133
{
134-
// Skip parameters that are injected as services
135-
if (parameter.IsServiceParameter(fromServiceMetadataSymbol, fromKeyedServiceAttributeSymbol))
136-
{
137-
continue;
138-
}
139-
140134
// Find the corresponding property in this type, we ignore
141135
// base types here since that will be handled by the inheritance
142136
// checks in the default ValidatableTypeInfo implementation.
@@ -148,6 +142,12 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb
148142
{
149143
resolvedRecordProperty.Add(correspondingProperty);
150144

145+
// Skip parameters that are injected as services
146+
if (parameter.IsServiceParameter(fromServiceMetadataSymbol, fromKeyedServiceAttributeSymbol))
147+
{
148+
continue;
149+
}
150+
151151
// Check if the property's type is validatable, this resolves
152152
// validatable types in the inheritance hierarchy
153153
var hasValidatableType = TryExtractValidatableType(
@@ -173,8 +173,8 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb
173173
{
174174
// Skip compiler generated properties and properties already processed via
175175
// the record processing logic above.
176-
if (member.IsImplicitlyDeclared
177-
|| member.IsEqualityContract(wellKnownTypes)
176+
if (member.IsImplicitlyDeclared
177+
|| member.IsEqualityContract(wellKnownTypes)
178178
|| resolvedRecordProperty.Contains(member, SymbolEqualityComparer.Default))
179179
{
180180
continue;

src/Validation/test/Microsoft.Extensions.Validation.GeneratorTests/ValidationsGenerator.RecordType.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public record SubTypeWithoutConstructor
5050
5151
[StringLength(10)]
5252
public string? StringWithLength { get; set; }
53+
54+
[FromServices]
55+
[Required]
56+
public TestService ServiceProperty { get; set; } = null!;
5357
}
5458
5559
public static class CustomValidators

src/Validation/test/Microsoft.Extensions.Validation.GeneratorTests/snapshots/ValidationsGeneratorTests.CanValidateRecordTypes#ValidatableInfoResolver.g.received.cs

Lines changed: 0 additions & 292 deletions
This file was deleted.

0 commit comments

Comments
 (0)