Last active
April 4, 2020 10:13
-
-
Save DavidRogersDev/68b138eab612bb9da1603a00529f3257 to your computer and use it in GitHub Desktop.
Gist for Medium Article - ValidateableResponse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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