Created
January 14, 2014 14:56
-
-
Save scichelli/8419568 to your computer and use it in GitHub Desktop.
Blog comment from uvwu on http://lostechies.com/sharoncichelli/2014/01/13/maybe-that-shouldnt-be-settable/. Code transcribed by me, so blame me for any typos.
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 static class Result | |
{ | |
private const int UNKNOWN_STATUS_CODE = -1; | |
private const string UNKNOWN_STATUS_PHRASE = @"WAT?"; | |
public static Result<t> Success(T result = default(T)) | |
{ | |
return Result<t>.Success(new[] { result }); | |
} | |
public static Result<t> Error(int statusCode = UNKNOWN_STATUS_CODE, | |
string reasonPhrase = UNKNOWN_STATUS_PHRASE) | |
{ | |
return new Result<t>.Error(statusCode, reasonPhrase); | |
} | |
} |
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 static Result<t> ToResult<t>(this HttpResponseMessage response) | |
{ | |
return response.IsSuccessStatusCode | |
? Result.Success(Deserialize(response)) | |
: Result.Error<coolthing>(response.StatusCode, response.ReasonPhrase); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment