Skip to content

What is the way to combine multiple failures when T is different but E is the same? #377

Answered by xavierjohn
xavierjohn asked this question in Q&A
Discussion options

You must be logged in to vote

This is my solution and hopefully there is a better way.

I created an ErrorCollection class with an implicit operator to convert error.

    public sealed class ErrorCollection : ICombine
    {
        public ErrorCollection() => _errors = new List<Error>();
        public ErrorCollection(IEnumerable<Error> errors) => _errors = errors.ToList();
        public Error[] Errors { get => _errors.ToArray(); }
        public bool HasErrors => _errors.Any();

        public void Add(ErrorCollection ec) => _errors.AddRange(ec.Errors);

        private readonly List<Error> _errors;

        ICombine ICombine.Combine(ICombine value)
        {
            var errorCollection = (ErrorCollection)value;
…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by xavierjohn
Comment options

You must be logged in to vote
1 reply
@xavierjohn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants