Mad.Common

Compose results with C#.

Result

The result object is used for returning results with errors. This gives a uniformed way of returning validation errors.

There are two types of results. One with a Body Result<T> and one without a Body Result


Add Errors

Single Error
    myResult.AddError("Error1", "There was an error");
Chain Errors
    myResult.AddError("Error1", "There was an error")
            .AddError("Error2", "There was an error")
            .AddError("Error3", "There was an error");
Merge Results

The errors from each result will be added to the result.

        Result r1 = _someService1().Validate(someObj1);
        Result r2 = _someService2().Validate(someObj2);
        Result r3 = _someService3().Validate(someObj3);

        var myResult = Result.New()
            .AddErrors(r1, r2, r3);
Single Error If
myResult.AddErrorIf(true, "Error1", "There was an error");

Success & Failed

Success

Is true if there are no errors.

Failed

Is true if there are any errors.