Skip to content

Instantly share code, notes, and snippets.

@scichelli
Created January 14, 2014 14:56
Show Gist options
  • Save scichelli/8419568 to your computer and use it in GitHub Desktop.
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.
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);
}
}
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