private static ICollection<KeyValuePair<ValidationContext, object?>> GetPropertyValues(object instance,
ValidationContext validationContext)
{
- var properties = TypeDescriptor.GetProperties(instance);
+ var properties = TypeDescriptor.GetProperties(instance.GetType());
var items = new List<KeyValuePair<ValidationContext, object?>>(properties.Count);
foreach (PropertyDescriptor property in properties)
{
using System.Collections.Generic;
using System.Linq;
+using Newtonsoft.Json.Linq;
using Xunit;
namespace System.ComponentModel.DataAnnotations.Tests
Assert.Contains(validationResults, x => x.ErrorMessage == "The SecondPropertyToBeTested field is not a valid phone number.");
}
+ [Fact]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Framework has always thrown for this case. See https://github.com/dotnet/runtime/issues/64207")]
+ public static void TryValidateObject_for_JObject_does_not_throw()
+ {
+ var objectToBeValidated = JObject.Parse("{\"Enabled\":true}");
+ var results = new List<ValidationResult>();
+ Assert.True(Validator.TryValidateObject(objectToBeValidated, new ValidationContext(objectToBeValidated), results, true));
+ Assert.Empty(results);
+ }
+
public class RequiredFailure
{
[Required]