Microsoft.AspNetCore.Mvc.ActionResult<TValue> 返回其他常见信息



我想在类 Microsoft.AspNetCore.Mvc.ActionResult<> 的对象中返回其他公共信息。此信息应存储在新属性中。此类是密封的。我该怎么做?

我应该使用装饰器还是适配器图案?

也许应该以与使用新属性完全不同的方式返回这些额外的操作通用信息?

通常,为了返回其他公共信息,我们可以使用新的 ObjectResult(对象值(:

[HttpGet("{id}")]
public async Task<ActionResult<Localization>> Get(long id)
{
var item = await _context.Localizations.FindAsync(id);
if (item == null)
{
logger.Error(string.Format("LocalizationId: {0} not found.", id));
return new ObjectResult(new DataActionResult(ResultActionCodes.ItemNotFound, string.Format("LocalizationId: {0} not found.", id))); ;
}
return item;
}

最新更新