// ========================================================================== // 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.Linq; using System.Threading.Tasks; namespace Squidex.Infrastructure { public static class Validate { public static void It(Func message, Action> action, IReadOnlyDictionary messages = null) { var errors = new List(); action(errors.Add); if (errors.Any()) { throw new ValidationException(message(), errors); } } public static async Task It(Func message, Func, Task> action, IReadOnlyDictionary messages = null) { var errors = new List(); await action(errors.Add); if (errors.Any()) { throw new ValidationException(message(), errors); } } } }