. Net is easier to use the configuration file SuperConfig,. netsuperconfig

Source: Internet
Author: User

. Net is easier to use the configuration file SuperConfig,. netsuperconfig
I. original configuration file Problems

During our development, almost all projects, whether B/S or C/S, will useConfiguration File, Such as the link string, upload path, and API address. The complexity is more, such as ActiveMQ configuration information (address, port, user name, password) and so on.

In. Net development, a relatively complete configuration system has been provided in (Web. config/App. config). simple configuration systems include:AppSettings; complex: sectionI believe you will have used it. Of course, you can add references first when using the configuration file:"System. Configuration";

As mentioned above, when many items need to be configured in the configuration file, there is a lot of inconvenience in the original configuration file. This article is to tell you how to use the configuration file more easily when you configure multiple items.

 

Ii. ideas and solutions a) and B). Solutions

At present, LZ does not find a better configuration file in. Net, so LZBut I wrote one myself.To implement what I call the "idea" and put it open-sourceGithubAnd upload themNugetFor your convenience.

 

Iii. Emrys. SuperConfig

Github: https://github.com/Emrys5/Emrys.SuperConfig welcome everyone Star _ ^

Https://www.nuget.org/packages/Emrys.SuperConfig: Nuget

Wiki: https://github.com/Emrys5/Emrys.SuperConfig/wiki

 

Iv. Simple Application of Emrys. SuperConfig

 

You only need one line of code to obtain all the configuration information. You can useEasy to useTo describe.

 

IV. Other Emrys. SuperConfig

 

1. supported data types

Common data types include String, Int, Double, DateTime, Bool, and Enum.

For more complex types such as KeyValuePair/Array/List/Dictionary, see Wikipedia: Data Types supported

 

2. Custom configuration file location

In actual development, we may not place the configuration file in the default Web. config/App. config, such as configuring user information separately.

For more information, see Wiki: custom configuration file location

 

3. Custom configuration file naming rules

During development, the naming rules of many programmers are not uniform, and Case sensitivity issues may occur. The names include the names of element and Attribute in xml.

SuperConfig usesLowercase lettersThat is, the small hump.

For more information, see Wiki: custom configuration file naming rules.

 

4. Custom Section format

In the original configuration file, we need to customize the configuration file, so we need to configure the section in the configuration file, such as our common EntityFramework.

If we customize the location of the configuration file, we do not need to use the original configuration file, so we do not need to create a Section in configSections every time according to the previous configuration method, and then in the configuration.

You can customize the configuration file format, for example:

<?xml version="1.0" encoding="utf-8" ?> <config>  <userInfo userName="CEmrys" email="i@emrys.me" age="17">    <blogUrl>http://www.cnblogs.com/emrys5/</blogUrl>    <favoriteColor>Blue</favoriteColor>    <dislikeColor>2</dislikeColor>  </userInfo>  <arrayString>    <item>a</item>    <item>b</item>    <item>c</item>    <item>d</item>    <item>e</item>  </arrayString></config>

For more information, see Wiki: Custom Section format

 

V. Summary

Given that LZ is not convenient enough to use the configuration file in. Net and does not find a proper method on the Internet, all of them write one according to their own ideas and hope it will be helpful to everyone.

Don't forget"RecommendationAndGithub StarThank you!

Github: https://github.com/Emrys5/Emrys.SuperConfig welcome everyone Star _ ^

Https://www.nuget.org/packages/Emrys.SuperConfig: Nuget

Wiki: https://github.com/Emrys5/Emrys.SuperConfig/wiki

 

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.