Skip to content

Instantly share code, notes, and snippets.

@vkhorikov
Created July 3, 2015 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkhorikov/7df31ddd7bdc066623c4 to your computer and use it in GitHub Desktop.
Save vkhorikov/7df31ddd7bdc066623c4 to your computer and use it in GitHub Desktop.
public void Create(string name, string email, string billingInfo)
{
Result<CustomerName> nameResult = CustomerName.Create(name);
Result<Email> emailResult = Email.Create(email);
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo);
return Result.Combine(nameResult, emailResult, billingInfoResult)
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value));
/* Other OnSuccess, OnFailure, OnBoth methods */
}
public class Result
{
public bool Success { get; private set; }
public string[] Errors { get; private set; }
public static Result Combine(params Result[] results)
{
if (results.Any(r => r.Failure))
{
string[] errors = results.SelectMany(r => r.Errors).ToArray();
return Fail(errors);
}
return Ok();
}
/* Other members as before */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment