-
Notifications
You must be signed in to change notification settings - Fork 13
2. Support for data types
Emrys edited this page Jan 25, 2018
·
1 revision
Common data types support String, Int, Double, DateTime, Bool, Enum and so on. These are simple data types directly used.
<userInfo
userName='Emrys'
email='i@emrys.me'
age='27'
blogUrl='http://www.cnblogs.com/emrys5/'
favoriteColor='Blue'
dislikeColor='2'
></userInfo>
<userInfo>
<userName>Emrys</userName>
<email>i@emrys.me</email>
<age>27</age>
<blogUrl>http://www.cnblogs.com/emrys5/</blogUrl>
<favoriteColor>Blue</favoriteColor>
<dislikeColor>2</dislikeColor>
</userInfo>
of course, can be mixed, so it can be conveniently configured
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="sport" type="Emrys.SuperConfig.Section,Emrys.SuperConfig"></section>
</configSections>
<sport>
<key>2</key>
<value>Football</value>
</sport>
</configuration>
var sport = SuperConfig.Mapping<KeyValuePair<int, string>>("sport");
Assert.AreEqual(sport.Key, 2);
Assert.AreEqual(sport.Value, "Football");
- in the configuration config, the names of key and value are not the same as the values set in the ConvertCase in the Setting, and the default is key and value.
- also key value also supports setting values in Attribute
<sport key="2" value="Football">
</sport>
The usage of List and Array is similar to the configuration, so here is only the use of List.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="listString" type="Emrys.SuperConfig.Section,Emrys.SuperConfig"></section>
</configSections>
<listString>
<item>a</item>
<item>b</item>
<item>c</item>
<item>d</item>
</listString>
</configuration>
var listString = SuperConfig.Mapping<List<string>>("listString");
Assert.AreEqual(listString.First(), "a");
Assert.AreEqual(listString.Count, 4);
- in List, subitems must be configured with Element, and the name can be customized.
- in List, it can contain simple types, such as String, Int, Double, DateTime, Bool, Enum, etc., and can also contain entity objects. Of course, List can be included as long as SuperConfig supports, such as:
<family>
<item userName='lcz' email='xxx@qq.com' age='50'></item>
<item>
<userName>ly</userName>
<email>ly@qq.com</email>
<age>30</age>
</item>
</family>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="dictionaryIntString" type="Emrys.SuperConfig.Section,Emrys.SuperConfig"></section>
</configSections>
<dictionaryIntString>
<item key="1" value="a"></item>
<item>
<key>2</key>
<value>b</value>
</item>
</dictionaryIntString>
</configuration>
var dic = SuperConfig.Mapping<Dictionary<int, string>>("dictionaryIntString");
Assert.AreEqual(dic.First().Key, 1);
Assert.AreEqual(dic.Last().Value, "b");
- in Dictionary, the t name of key and value is the same as the values set by ConvertCase in Setting, and the default is key and value.
- in Dictionary, it can contain simple types, such as String, Int, Double, DateTime, Bool, Enum, etc., and can also contain entity objects. Of course, List can be included as long as SuperConfig supports, such as:
<colleagues>
<colleague>
<key>1</key>
<value>
<userName>zfx</userName>
<email>wy@qq.com</email>
<age>100</age>
</value>
</colleague>
<colleague>
<key>2</key>
<value>
<userName>zk</userName>
<email>zk@qq.com</email>
<age>30</age>
</value>
</colleague>
</colleagues>