简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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