Skip to content

Commit

Permalink
Update (#21)
Browse files Browse the repository at this point in the history
- Fixed `null` property value default validation (needs to be skipped, because the default behavior of .NET validation attributes is to return an error for a `null` value)
  • Loading branch information
nd1012 authored Oct 21, 2023
1 parent 9195c1d commit 063665c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ObjectValidation/ObjectValidation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>1.12.1</Version>
<Version>1.12.2</Version>
<DebugType>embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
</PropertyGroup>
Expand Down
11 changes: 7 additions & 4 deletions src/ObjectValidation/ValidationExtensions.Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,14 @@ orderby pi.Name
noValidation = noValidationAttr is not null;
if (isObjectValidatable)
{
validationContext = new(obj, serviceProvider, items: null)
if (value is not null)
{
MemberName = pi.Name
};
res &= Validator.TryValidateProperty(value, validationContext, validationResults);
validationContext = new(obj, serviceProvider, items: null)
{
MemberName = pi.Name
};
res &= Validator.TryValidateProperty(value, validationContext, validationResults);
}
if (noValidation && noValidationAttr!.SkipNullValueCheck)
{
#if DEBUG
Expand Down

0 comments on commit 063665c

Please sign in to comment.