-
Notifications
You must be signed in to change notification settings - Fork 1
Result
Hamed ZVand edited this page Sep 17, 2019
·
3 revisions
The Result data type is a container for an element of the given type or null.
It's created for this purpose to return more (useful) information to the (service) caller. Like for something that can partially succeed, something calling across a network boundary, and provide further information about error or warning consisting of StatusCode and Message.
Samples:
private Result<Foo> ExternalService()
{
// do some network comunication and return value
var value = new Foo("bar");
return Result<Foo>.Okay(value);
// return Result<Foo>.Exception(new TimeoutException());
// return Result<Foo>.Error("something bad happend");
}
public Foo Demo1()
{
var result = ExternalService();
if(result)
{ return result.Data; }
else
{
_logger.LogError(result.Message);
return NotFound();
}
}