Skip to content

Commit cabe2b1

Browse files
Copilotcaptainsafia
andcommitted
Remove unused IsJsonIgnoredParameter method and clean up test snapshots
- Remove IsJsonIgnoredParameter method since JsonIgnore can only be applied to properties and fields, not constructor parameters - Update record parameter validation to check corresponding property for JsonIgnore instead - Delete stale received snapshot file - Update verified snapshot to include record type validation results Co-authored-by: captainsafia <[email protected]>
1 parent d038ce7 commit cabe2b1

File tree

4 files changed

+18
-194
lines changed

4 files changed

+18
-194
lines changed

src/Validation/gen/Extensions/ITypeSymbolExtensions.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,4 @@ internal static bool IsJsonIgnoredProperty(this IPropertySymbol property, INamed
164164
attr.AttributeClass is not null &&
165165
SymbolEqualityComparer.Default.Equals(attr.AttributeClass, jsonIgnoreAttributeSymbol));
166166
}
167-
168-
/// <summary>
169-
/// Checks if the parameter is marked with [JsonIgnore] attribute.
170-
/// </summary>
171-
/// <param name="parameter">The parameter to check.</param>
172-
/// <param name="jsonIgnoreAttributeSymbol">The symbol representing the [JsonIgnore] attribute.</param>
173-
internal static bool IsJsonIgnoredParameter(this IParameterSymbol parameter, INamedTypeSymbol jsonIgnoreAttributeSymbol)
174-
{
175-
return parameter.GetAttributes().Any(attr =>
176-
attr.AttributeClass is not null &&
177-
SymbolEqualityComparer.Default.Equals(attr.AttributeClass, jsonIgnoreAttributeSymbol));
178-
}
179167
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb
150150
continue;
151151
}
152152

153-
// Skip parameters that have JsonIgnore attribute
154-
if (parameter.IsJsonIgnoredParameter(jsonIgnoreAttributeSymbol))
153+
// Skip properties that have JsonIgnore attribute
154+
if (correspondingProperty.IsJsonIgnoredProperty(jsonIgnoreAttributeSymbol))
155155
{
156156
continue;
157157
}

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

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

src/Validation/test/Microsoft.Extensions.Validation.GeneratorTests/snapshots/ValidationsGeneratorTests.CanValidateComplexTypesWithJsonIgnore#ValidatableInfoResolver.g.verified.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//HintName: ValidatableInfoResolver.g.cs
1+
//HintName: ValidatableInfoResolver.g.cs
22
#nullable enable annotations
33
//------------------------------------------------------------------------------
44
// <auto-generated>
@@ -77,6 +77,21 @@ public bool TryGetValidatableTypeInfo(global::System.Type type, [global::System.
7777
);
7878
return true;
7979
}
80+
if (type == typeof(global::RecordTypeWithJsonIgnore))
81+
{
82+
validatableInfo = new GeneratedValidatableTypeInfo(
83+
type: typeof(global::RecordTypeWithJsonIgnore),
84+
members: [
85+
new GeneratedValidatablePropertyInfo(
86+
containingType: typeof(global::RecordTypeWithJsonIgnore),
87+
propertyType: typeof(int),
88+
name: "ValidatedProperty",
89+
displayName: "ValidatedProperty"
90+
),
91+
]
92+
);
93+
return true;
94+
}
8095

8196
return false;
8297
}

0 commit comments

Comments
 (0)