我可以使用字典类型作为自定义服务器控件的(持久)属性吗?
我目前正在开发一个服务器控件,应通过键/值对列表进行配置,如下所示:
<MyControls:ContentRenderer ID="ContentRenderer1" runat="server">
<MyControls:Placeholders>
<MyControls:Placeholder key="ident1">Some text which replaces {ident1}</MyControls:Placeholder>
<MyControls:Placeholder key="ident2">Some text which replaces {ident2}</MyControls:Placeholder>
</MyControls:Placeholders>
<MyControls:ContentRenderer />
我希望该属性是一个字典,以便我可以通过标识符快速检索占位符映射。我知道如何使用 List< 创建一个与上述标记保持一致的属性。 T>类,但我想要一个类似哈希图的数据结构。
我在 msdn 上读了很多东西,但如果您想完全控制控件标记的解析方式,我仍然不知道该怎么做。
I'm currently developing a server control which should be configured via a list of key/value pairs, like this:
<MyControls:ContentRenderer ID="ContentRenderer1" runat="server">
<MyControls:Placeholders>
<MyControls:Placeholder key="ident1">Some text which replaces {ident1}</MyControls:Placeholder>
<MyControls:Placeholder key="ident2">Some text which replaces {ident2}</MyControls:Placeholder>
</MyControls:Placeholders>
<MyControls:ContentRenderer />
I want that property to be a dictionary so I can quickly retrieve placeholder mappings by their identifier. I know how to create a property which is persisted with the above markup by using the List< T > class but I'd like to have a hashmap-like datastructure.
I read a lot of stuff at msdn but I still have no clue what to do if you want full control over the way your control markup is parsed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为字典不以这种方式支持。然而,完成此操作的方法是使用自定义的基于列表的类,而不是使用列表,该类还存储键/对象的字典映射。
HTH。
I don't think dictionaries are supported in this way. However, the way this is done, is instead of using List, use a custom list-based class, which also stores a dictionary mapping of the key/object.
HTH.