fix(validation): return no problems for null reference instance in Rule.Validate

Rule<T,TProperty>.Validate cast a null instance to T and validated it, so a
reference T whose accessor dereferences the instance threw
NullReferenceException on a direct validator.Validate(context) with a null
instance. Guard the null-instance path and return no problems instead.
This commit is contained in:
Louis Seubert 2026-07-12 18:43:37 +02:00
commit 552f88df18
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
3 changed files with 13 additions and 1 deletions

View file

@ -46,7 +46,7 @@ internal abstract record Rule<T, TProperty> : Rule
if (context.Instance is null && default(T) is null)
{
return Validate((T)context.Instance!, context);
return [];
}
var actualType = context.Instance?.GetType().FullName ?? "null";