Custom Application configuration Node

Source: Internet
Author: User

During development, I believe that everyone will often deal with configuration files, whether it is the App. config file of the application or the Web. config file of the Web program. Today, I have nothing to worry about. I suddenly thought that I was using the *. config file for configuration parameters, but I have never developed a custom configuration node. I did a little research and wrote this article to record my learning experience.
The configuration files involved in this article are App. config and Collector. config.

App. config

                                                  

Collector. config

                     

The configuration node of Collector. config is separated from App. config to demonstrate the use of configSource. ConfigSource is only available in custom section nodes.

The development of custom configuration nodes mainly involves the following types:

CollectorSectionGroup inherits the nodes corresponding to the ConfigurationSectionGroup and is mainly used to define a set of custom nodes. The Code is as follows:

                     [ConfigurationProperty(, IsRequired =                         {  Sections[]    }

The BackupSection inherits from the nodes corresponding to the ConfigurationSection and is mainly used to define custom nodes. Class defines a Path attribute and a TriggedTimes element set attribute, corresponding to the node is and, respectively, the Code is as follows:

                     [ConfigurationProperty(, IsRequired =                          {  [               { [] =           [ConfigurationProperty(, IsRequired =          [ConfigurationCollection(                        {  []                { [] =   }

The TriggedTimeCollection inherits from the node corresponding to ConfigurationElementCollection. The Code is as follows:

                                                                   }

TriggedTime is inherited from the node corresponding to the ConfigurationElement. The Code is as follows:

                      [ConfigurationProperty(, IsRequired =                         {  (TimeSpan)[               { [] =   }

The Demo code mainly demonstrates the display

                      Main(                configuration =              sectionGroup = configuration.GetSectionGroup()               (sectionGroup !=                   sectionGroup.BackupSection.Path =                                                            configuration =              sectionGroup = (CollectorSectionGroup)configuration.GetSectionGroup(               (sectionGroup !=                    (TriggedTime triggedTime                       Console.WriteLine(     }

If you need to modify the Web. config configuration information of a Web application, unlike App. cnfig, you need to use the WebConfigurationManager class instead of the ConfigurationManager class. The Code is as follows:

                  configuration = WebConfigurationManager.OpenWebConfiguration(                  settings =                 settings.Remove(                 settings.Add(                 configuration.Save();

Click here to download the Code involved in this article.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.