DD.WellWorkover.Cloud/AsbCloudInfrastructure/ValidationExtensions.cs
2024-02-12 15:25:18 +03:00

17 lines
621 B
C#

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudInfrastructure;
public static class ValidationExtensions
{
public static bool Validate(this IValidatableObject validatableObject, ICollection<ValidationResult> validationResults)
{
var validationContext = new ValidationContext(validatableObject, serviceProvider: null, items: null);
foreach (var validationResult in validatableObject.Validate(validationContext))
validationResults.Add(validationResult);
return Validator.TryValidateObject(validatableObject, validationContext, validationResults, true);
}
}