【发布时间】:2023-01-18 00:37:03
【问题描述】:
我正在编写基于某些配置生成 C++ 文件的 C# 解决方案。为此,我使用 Scriban 作为模板引擎。之前在Jinja2看到过如下语句:
uint16_t {{"%25s"|format(device.name)}} = {{"0x%08x"|format(device.address)}};
device.name 是一个字符串,device.address 包含十六进制值 (0x50060800)。
我试过这个:
uint16_t {{device.name | object.format "%25s"}} = {{device.address | math.format "0x%08x"}};
我收到以下错误:
<input>(15,50) : error : Unexpected `RNG`. Must be a formattable object
<input>(15,71) : error : Unexpected `0x50060800`. Must be a formattable object
这是我期待的结果:
uint16_t RNG = 0x50060800;
我怎样才能在 Scriban 中实现上述声明?
【问题讨论】:
-
您能否在提供变量的模板周围添加 C# 代码?现在看起来您不需要格式化任何东西,因为值
RNG和0x50060800已经是预期的形式(尤其是字符串RNG,格式字符串%25s的目标是什么?)