开发者

How do I create custom sections in my app.config?

I'd like to add a custom section to my app.config. In that section, I'd like to add rows with three pieces of data. Then, I'd like to read my app.config (the custom section) and build a collection of items.

Can I create a customer section? If so, how do I create the section and how do I read i开发者_开发知识库tems in it?

Thanks!


MSDN covers very throughly everything that you need on this topic. See How to: Create Custom Configuration Sections Using ConfigurationSection, System.Configuration.ConfigurationSection and the links therein.


You would create a custom section group and a handler to deal with that section group. The process is outlined the associated in MSDN article:

http://msdn.microsoft.com/en-us/library/2tw134k3.aspx


You'd create a descendant of ConfigurationSection. Microsoft's documentation contains an example of how to use it to make custom app.config sections.


The CodeProject article Unraveling the Mysteries of .NET 2.0 Configuration is probably the best piece I've seen on the hoops you need to jump through to build a custom config section.

There's also, the Coding Horror's Last Configuration Section Handler I'll Ever Need and The Last Configuration Section Handler...Revisited, which avoid the problem by creating a generic XMLSerializationHandler: all you need to do is provide an class that is XML serializable. Easy!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜