public class ModalTitleDecorator : ActionResult
{
private readonly IActionResult _actionResult;
private readonly string _modalTitle;
public ModalTitleDecorator(IActionResult action, string modalTitle)
{
_actionResult = action;
_modalTitle = modalTitle;
}
public override async Task ExecuteResultAsync(ActionContext context)
{
var tempData = context.HttpContext.RequestServices.GetService<ITempDataDictionaryFactory>()
.GetTempData(context.HttpContext);
//always null...I assume that ViewData is not available according to HttpContext.
//TempData is available probably according to passing into next request.
var viewData = context.HttpContext.RequestServices.GetService<ViewDataDictionary>();
//something like this would be great
ViewData["Title"] = _modalTitle;
await _actionResult.ExecuteResultAsync(context);
}
}
我们可以通过理解使它成一行吗?
答案 0 :(得分:1)
IIUC,也许您正在寻找这种嵌套的理解
strats_having_fcs = {a.strategy: a.algorithmType for s in strategies for a in s.algorithms
if a.algorithmType == AlgorithmTypeEnum.feedback_control.value}
答案 1 :(得分:1)
只是:
strats_having_fcs = {a.strategy: a.algorithmType for s in strategies for a in s.algorithms if a.algorithmType == AlgorithmTypeEnum.feedback_control.value}
看看this这样的关于列表内理解的问题。对我来说,这澄清了很多背后的逻辑。