andrebaltieri / Flunt

Validations and Notifications
https://github.com/andrebaltieri/flunt
MIT License
624 stars 162 forks source link

Minimizing impact of Contract class changes #90

Closed yanjustino closed 3 years ago

yanjustino commented 3 years ago

The problem

Current changes in the Contract class have caused crashes in Flunt extendable packages such as Flunt.Br.

The solution

In view of the continuity of the operation of these packages, I make the following suggestion:


    //Add this basic class
    public partial class Contract : Contract<bool> { };

    public partial class Contract<T> : Notifiable<Notification>
    {
        public Contract<T> Requires()
        {
            return this;
        }

        public Contract<T> Join(params Notifiable<Notification>[] items)
        {
            if (items == null) return this;
            foreach (var notifiable in items)
            {
                if (notifiable.IsValid == false)
                    AddNotifications(notifiable.Notifications);
            }

            return this;
        }
    }

justification

Since T is not a state of Contract, there would be no major implications of maintaining a base class.

andrebaltieri commented 3 years ago

We already have an implementation of these extensions here: https://github.com/andrebaltieri/Flunt.Extensions.Br

Does it sounds good?

yanjustino commented 3 years ago

Sounds great!

Greate work, @andrebaltieri !