Skip to content

4. Custom config file naming rules

Emrys edited this page Jan 25, 2018 · 1 revision

In the development, there are many people in the programmer's naming rules are not very uniform, and all the problem of name and size will appear. The name of the element and Attribute that contains the XML is named.

1. Default

In the default SuperConfg, the name of the configuration file is lowercase, that is, small hump, such as:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="userInfo" type="Emrys.SuperConfig.Section,Emrys.SuperConfig"></section> 
  </configSections> 
  <userInfo userName="FEmrys" email="i@emrys.me" age="17">
    <blogUrl>http://www.cnblogs.com/emrys5/</blogUrl>
    <favoriteColor>Blue</favoriteColor>
    <dislikeColor>2</dislikeColor>
  </userInfo>  
</configuration>

2. custom naming rules=>Consistent with the name of the property

For example, some programmers prefer the name of the hump in the configuration file, that is, the name is always named after the attribute we configured, because in the development of C#, the attributes are usually named "Hump".

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections> 
    <section name="UserInfo" type="Emrys.SuperConfig.Section,Emrys.SuperConfig"></section>
  </configSections> 
  <UserInfo UserName="Emrys" Email="i@emrys.me" Age="27">
    <BlogUrl>http://www.cnblogs.com/emrys5/</BlogUrl>
    <FavoriteColor>Blue</FavoriteColor>
    <DislikeColor>2</DislikeColor>
  </UserInfo> 
</configuration>

2.1 Setting

SuperConfig<UserInfo>.Setting(n => n);

2.2 Get value

var user = SuperConfig<UserInfo>.Value;

3. custom naming rules=>All uppercase

SuperConfig<UserInfo>.Setting(n => n.n.ToUpper());

In a word, the naming rules are changed with you, but to be unified, that is, Element and Attribute want one value.