Skip to content

[feat] Support multiple validation errors #68

@cnblogs-dudu

Description

@cnblogs-dudu

Code is worth a thousand words.

public record CreateOrderCommand(CreateOrderDto Dto, bool ValidateOnly)
    : ICommand<long, OrderError>, IValidatable
{
    public IEnumerable<ValidationError>? Validate()
    {
        ICollection<ValidationResult>? results = null;
        if (!Validator.TryValidateObject(Dto, new ValidationContext(Dto), results, true))
        {
            return results?.Select(r => new ValidationError(r.ErrorMessage, r.MemberNames.First()));
        }

        return null;
    }
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions