我想在我的代码中使用新开关,用于方法结果 make log 和 return IActionResult
。
我尝试做这样的事情:
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");
}
};
但是编译器对我说cannot convert lambda expression to type 'IActionResult' because it is not a delegate type
。
我该如何解决?