Compose results with C#.
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
myResult.AddError("Error1", "There was an error");
myResult.AddError("Error1", "There was an error") .AddError("Error2", "There was an error") .AddError("Error3", "There was an error");
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);
myResult.AddErrorIf(true, "Error1", "There was an error");
Is true if there are no errors.
Is true if there are any errors.