I want to use new switch in my code, that for method result make log and return IActionResult
.
I try to do something like this:
var response = (this._coreRepository.Write(value.Content, data.Id.ToString())); \\return bool
return response switch
{
true => () =>
{
this._log.LogInformation("Write is complited");
return Ok();
},
false => () =>
{
this._log.LogInformation("Error in writing");
return BadRequest();
},
_ => () =>
{
throw new Exception("Unexpected error");
}
};
But compiler says to me cannot convert lambda expression to type 'IActionResult' because it is not a delegate type
.
How can I fix it?