Skip to content

Instantly share code, notes, and snippets.

@scichelli
Created January 11, 2014 20:07
Show Gist options
  • Save scichelli/8376021 to your computer and use it in GitHub Desktop.
Save scichelli/8376021 to your computer and use it in GitHub Desktop.
public class Result<T>
{
public bool IsSuccess { get; private set; }
public string ErrorMessage { get; private set; }
public IEnumerable<T> Results { get; private set; }
private Result()
{ }
public static Result<T> Success(IEnumerable<T> results)
{
return new Result<T>
{
IsSuccess = true,
Results = results
};
}
public static Result<T> Success(T result)
{
return Success(new[] { result });
}
public static Result<T> Error(int statusCode, string reasonPhrase)
{
return new Result<T>
{
ErrorMessage = string.Format("Error {0}: {1}", statusCode, reasonPhrase),
Results = Enumerable.Empty<T>()
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment