Headless CMS and Content Managment Hub
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.
 
 
 
 
 

41 lines
1.3 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Core.Rules
{
public abstract class RuleAction : Freezable
{
public IEnumerable<ValidationError> Validate()
{
var context = new ValidationContext(this);
var errors = new List<ValidationResult>();
if (!Validator.TryValidateObject(this, context, errors, true))
{
foreach (var error in errors)
{
yield return new ValidationError(error.ErrorMessage, error.MemberNames.ToArray());
}
}
foreach (var error in CustomValidate())
{
yield return error;
}
}
protected virtual IEnumerable<ValidationError> CustomValidate()
{
yield break;
}
}
}