Skip to content

Instantly share code, notes, and snippets.

@DavidRogersDev
Last active April 4, 2020 10:13
Show Gist options
  • Save DavidRogersDev/68b138eab612bb9da1603a00529f3257 to your computer and use it in GitHub Desktop.
Save DavidRogersDev/68b138eab612bb9da1603a00529f3257 to your computer and use it in GitHub Desktop.
Gist for Medium Article - ValidateableResponse
public class ValidateableResponse
{
private readonly IList<string> _errorMessages;
public ValidateableResponse(IList<string> errors = null)
{
_errorMessages = errors ?? new List<string>();
}
public bool IsValidResponse => !_errorMessages.Any();
public IReadOnlyCollection<string> Errors => new ReadOnlyCollection<string>(_errorMessages);
}
public class ValidateableResponse<TModel> : ValidateableResponse
where TModel : class
{
public ValidateableResponse(TModel model, IList<string> validationErrors = null)
: base(validationErrors)
{
Result = model;
}
public TModel Result { get; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment