CodeDom 和集合初始值设定项
有没有办法使用 C# CodeDom 生成字典初始值设定项?这些都受支持吗?
我想要:
private IDictionary<string, string> map = new Dictionary<string, string>
{
{ "Name", "Value" },
...
};
Is there a way to generate a dictionary initializer using the C# CodeDom? Are those supported at all?
I would like to have:
private IDictionary<string, string> map = new Dictionary<string, string>
{
{ "Name", "Value" },
...
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 CodeDom 构造这是不可能的。它们没有针对集合初始值设定项进行更新。
LukeH 有一篇关于 3.5 功能和 CodeDom 主题的精彩博客文章
This is not possible using the CodeDom constructs. They were not updated for collection initializers.
LukeH has an excellent blog post on the subject of 3.5 features and the CodeDom
你可以做到,但这可能是有史以来最糟糕的噩梦......这就是我目前正在做的事情。 (更新了我的答案以反映问题)
这也可以再次填充它的黑客行为。
You can do it but its possibly the worst nightmare ever.. Here is how I am doing it currently. (Updated my answer to reflect the question)
This can also be populated once again its hackish.