简体   繁体   English

我可以将Dictionary类型用作自定义服务器控件的(persistet)属性吗?

[英]Can I use the Dictionary type as a (persistet) property of a custom server control?

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. 我知道如何使用List <T>类创建一个保留上述标记的属性,但我想拥有一个类似于哈希图的数据结构。

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. 我在msdn上读了很多东西,但是如果您想完全控制控件标记的解析方式,我仍然不知道该怎么做。

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. 但是,完成此操作的方法不是使用List,而是使用基于列表的自定义类,该类还存储键/对象的字典映射。

HTH. HTH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM