// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschränkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using System.Collections.Generic; using System.Threading.Tasks; namespace Squidex.Infrastructure.Validation { public static class Validate { public static void It(Action action) { List? errors = null; var addValidation = new AddValidation((m, p) => { errors ??= new List(); errors.Add(new ValidationError(m, p)); }); action(addValidation); if (errors != null) { throw new ValidationException(errors); } } public static async Task It(Func action) { List? errors = null; var addValidation = new AddValidation((m, p) => { errors ??= new List(); errors.Add(new ValidationError(m, p)); }); await action(addValidation); if (errors != null) { throw new ValidationException(errors); } } } public delegate void AddValidation(string message, params string[] propertyNames); }