forked from ddrilling/AsbCloudServer
17 lines
649 B
C#
17 lines
649 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);
|
|
}
|
|
} |