andrebaltieri / Flunt

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

Creating standardized return notifications #43

Closed silvairsoares closed 3 years ago

silvairsoares commented 4 years ago

Creation of functionality to return validation failures in the following pattern: [ "property 1": "failure" "property 2": "failure" ... ]

natancmacedo commented 4 years ago

You can use Linq, like this:

 public class Program
    {
        class MyClass : Notifiable
        {
            public string Name { get; private set; }

            public MyClass(string name)
            {
            Name = name;
            AddNotifications(new Contract()
                .Requires()
                .IsNotNullOrEmpty(Name, nameof(Name), "Name cannot be null"));
        }
    }

    public static void Main()
    {
        var myClassInstance = new MyClass(null);

        List<string> myList = myClassInstance.Notifications.Select(n => $"{n.Property} : {n.Message}").ToList();
    }
}`

to achieve the same result.

silvairsoares commented 4 years ago

@natancmacedo Thanks for the suggestion, I opened a new pull #46, changing to use Linq.

andrebaltieri commented 3 years ago

Ill resolve this by removing <code>sealed</code> modifier from <code>Notification</code> class on next release! Then youll be able to extend it and create your own notification!

silvairsoares commented 3 years ago

Ill resolve this by removing <code>sealed</code> modifier from <code>Notification</code> class on next release! Then youll be able to extend it and create your own notification!

Thank you!