简体   繁体   English

如何在我的app.config中创建自定义部分?

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

I'd like to add a custom section to my app.config. 我想在我的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. 然后,我想阅读我的app.config(自定义部分)并构建项目集合。

Can I create a customer section? 我可以创建客户部分吗? If so, how do I create the section and how do I read items in it? 如果是这样,我如何创建该节以及如何阅读其中的项目?

Thanks! 谢谢!

MSDN covers very throughly everything that you need on this topic. MSDN完全涵盖了您在此主题上需要的所有内容。 See How to: Create Custom Configuration Sections Using ConfigurationSection , System.Configuration.ConfigurationSection and the links therein. 请参阅如何:使用ConfigurationSectionSystem.Configuration.ConfigurationSection及其中的链接创建自定义配置节

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: MSDN文章中概述了相关的过程:

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

You'd create a descendant of ConfigurationSection . 您将创建ConfigurationSection的后代。 Microsoft's documentation contains an example of how to use it to make custom app.config sections. Microsoft的文档包含一个示例,说明如何使用它制作自定义的app.config部分。

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. CodeProject文章“ 揭开.NET 2.0配置的奥秘”可能是我在构建自定义配置部分时需要克服的最棒的知识。

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. 还有, 我将永远需要Coding Horror最后一个配置节处理程序最后一个配置节处理程序... Revisited ,它们通过创建一个通用XMLSerializationHandler来避免此问题:您所要做的就是提供一个XML类序列化。 Easy! 简单!

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

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