mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
// ==========================================================================
|
|
// 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<AddValidation> action)
|
|
{
|
|
List<ValidationError>? errors = null;
|
|
|
|
var addValidation = new AddValidation((m, p) =>
|
|
{
|
|
errors ??= new List<ValidationError>();
|
|
errors.Add(new ValidationError(m, p));
|
|
});
|
|
|
|
action(addValidation);
|
|
|
|
if (errors != null)
|
|
{
|
|
throw new ValidationException(errors);
|
|
}
|
|
}
|
|
|
|
public static async Task It(Func<AddValidation, Task> action)
|
|
{
|
|
List<ValidationError>? errors = null;
|
|
|
|
var addValidation = new AddValidation((m, p) =>
|
|
{
|
|
errors ??= new List<ValidationError>();
|
|
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);
|
|
}
|