如何重构这段代码?
ulong get_item_action_id = log.LogAction(iteration_id, "GET_ITEM_SERVICE");
try
{
p = serv.GetItemById(get_item_action_id, ls.externalItem.item);
}
catch (Exception exc)
{
log.LogActionResult(get_item_action_id, false, exc);
continue;
}
log.LogActionResult(get_item_action_id, true);
这里的场景是:
- 记录尝试获取操作并检索记录的操作 id (
ulong get_item_action_id = log.LogAction(iteration_id, "GET_ITEM_SERVICE");
) - 正确地,行动 (
p = serv.GetItemById(get_item_action_id, ls.externalItem.item);
) - 记录成功或失败结果(
log.LogActionResult(get_item_action_id, false, exc);
或log.LogActionResult(get_item_action_id, true);
)
所以,我想我可以使用一些代表来重写它,但是如何呢?