stringtemplate .net 动态对象
我正在使用字符串模板来呈现一些内容,但内容可能是可变的,因此不确定如何传递它(使用.net / c#)
基本想法是我有一个 List>需要最终作为参数,例如
List<KeyValuePair<string, object>> ret = new List<KeyValuePair<string, object>>();
ret.Add(new KeyValuePair<string, object>("elem1", true));
ret.Add(new KeyValuePair(string, object>("elem2", false));
现在我希望这些在字符串模板中显示为:
$item.elem1$ $item.elem2$
我可以让它们成为 $elem1$ 或 $elem2$ 但我需要它们在结构内部。因此,我实际上需要说服字符串模板 setAttribute 我正在传递具有属性 elem1 和 elem2 的对象,而实际上我有一个 KeyValuePairs 列表。
谢谢
I am using string template to render some content, but the content may be variable so not sure how to pass it in (using .net / c#)
Basic idea is I have a List> which need to end up as parameters, e.g.
List<KeyValuePair<string, object>> ret = new List<KeyValuePair<string, object>>();
ret.Add(new KeyValuePair<string, object>("elem1", true));
ret.Add(new KeyValuePair(string, object>("elem2", false));
Now I want these to show up in string template as:
$item.elem1$
$item.elem2$
I can get them to be $elem1$ or $elem2$ but i need them inside of a structure. So I in effect need to convince the string template setAttribute that I'm passing in an object with properties elem1 and elem2 when in fact I have a List of KeyValuePairs.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,对其进行很小的重写就应该可以工作。您需要使用字典,甚至可以嵌套它们(使用 ST 3.2):
我自己和一位同事正在寻求复制 STST(ST 独立工具)的功能,它使用 json 作为属性,我们构建了一个简单的 JObject对于字典转换器,我可以发布该代码和示例(如果它对您有用的话),它只有大约 20 行。
Actually a very small re-write of that should work. You need to use a dictionary, and you can even nest them (using ST 3.2):
Myself and a colleague were looking to replicate the functionality of STST (ST Standalone Tool), which uses json as the properties, and we built a simple JObject to dictionary converter, I can post that code and an example if it's of any use to you, it's only ~20 lines.
ExpandoObject 的成员可以动态添加和删除运行时间。
ExpandoObject's members can be dynamically added and removed at run time.