????ProfileDictionary.json
1: {
2:   "profiles": {
3:     "foo": {
4:       "gender" : "Male"??
5:       "age"   : "18"??
6:       "contactInfo": {
7:         "email"      : "foo@outlook.com"??
8:         "phoneNo"    : "123"
9:       }
10:     }??
11:     "bar": {
12:       "gender" : "Male"??
13:       "age"   : "25"??
14:       "contactInfo": {
15:         "email"      : "bar@outlook.com"??
16:         "phoneNo"    : "456"
17:       }
18:     }??
19:     "baz": {
20:       "gender": "Female"??
21:       "age"   : "40"??
22:       "contactInfo": {
23:         "email"      : "baz@outlook.com"??
24:         "phoneNo"    : "789"
25:       }
26:     }
27:   }
28: }
???????????漲???????JSON??????????????????μ????????????JsonConfigurationProvider?????ConfigurationBuilder?С?????????ConfigurationBuilder?????Configuration?????????????e?????????????Profile??Profile[]??Dictionary<string??Profile>????
1: Profile profile = new ConfigurationBuilder()
2:     .AddJsonFile("Profile.json")
3:     .Build()
4:     .Get<Profile>("Profile");
5:
6: Profile[] profileArray = new ConfigurationBuilder()
7:     .AddJsonFile("ProfileCollection.json")
8:     .Build()
9:     .Get<Profile[]>("Profiles");
10:
11: Dictionary<string?? Profile> profileDictionary = new ConfigurationBuilder()
12:     .AddJsonFile("ProfileDictionary.json")
13:     .Build()
14: .Get<Dictionary<string?? Profile>>("Profiles");
????????XmlConfiguationProvider
????XML????????????????????????????????????????????JSON?????????????????????????????XML?????????????????????XML?????????????????????????????????????XML??????????????????????????????????????????????????????XML?????????Attribute??????????Profile??????????????????????????????????塣
????1: <Profile>
????2:   <Gender>Male</Gender>
????3:   <Age>18</Age>
????4:   <ContactInfo>
????5:     <Email>foobar@outlook.com</Email>
????6:     <PhoneNo>123456789</PhoneNo>
????7:   </ContactInfo>
????8: </Profile>
????????
????1: <Profile Gender="Male" Age="18">
????2:   <ContactInfo Email="foobar@outlook.com" PhoneNo="123456789"/>
????3: </Profile>
???????XML???????????????????????JSON?????????????????????????????????????????????????????????????е????????????????????????????????????Profile???????????????t??????????XML???????
1: <Profiles>
2:   <Profile Gender="Male" Age="18">
3:     <ContactInfo Email="foobar@outlook.com" PhoneNo="123"/>
4:   </Profile>
5:   <Profile Gender="Male" Age="25">
6:     <ContactInfo Email="bar@outlook.com" PhoneNo="456"/>
7:   </Profile>
8:   <Profile Gender="Male" Age="40">
9:     <ContactInfo Email="baz@outlook.com" PhoneNo="789"/>
10:   </Profile>
11: </Profiles>
???????????XML???????????????????????????????Profile?????????XML????<Profile>...</Profile>????“???”?????????????????????Profile?????????????????????????????????綽??????????????·??????????????????????????????????Key?????????????????????????????????????????????Profile???????????????????????μ???????????????????0??1??2??…?????·??????????
????1: 0:Gender
????2: 0:Age
????3: 0:ContactInfo:Email
????4: 0:ContactInfo:PhoneNo
????5:
????6: 1:Gender
????7: 1:Age
????8: 1:ContactInfo:Email
????9: 1:ContactInfo:PhoneNo
????10:
????11: 2:Gender
????12: 2:Age
????13: 2:ContactInfo:Email
????14: 2:ContactInfo:PhoneNo
???????????????????????????????????????????????????XML??????????????Name?????????Сд???????????????XML????????????Name?????????????????????????????????????????????·??????????????????????????????????<ContactInfo>????а??????μ?????????????“Foobar”??Name?????Email??PhoneNo??????????е?Key?????ж??????“Foobar”??
????1: <ContactInfo Name="Foobar" Email="foobar@outlook.com" PhoneNo="123"/>
????2:
????3: Keys??
????4: ContactInfo:Foobar:Email
????5: ContactInfo:Foobar:PhoneNo
?????????XML??????????Profile??????????????????μ?????<Profile>???????????Name????????????????????????????????????????????????????????????????????????????????????????????“Name”?????????????????XML??????????????????????????????Profile??????????Name????????????????????????????????????XML???????????????????????????XML?????Configuration?????Profile?????·????“Profiles:Profile”??????“Profiles”???????ú?????
1: <Profiles>
2:   <Profile Name="0" Gender="Male" Age="18">
3:     <ContactInfo Email="foobar@outlook.com" PhoneNo="123"/>
4:   </Profile>
5:   <Profile Name="1" Gender="Male" Age="25">
6:     <ContactInfo Email="bar@outlook.com" PhoneNo="456"/>
7:   </Profile>
8:   <Profile Name="2" Gender="Male" Age="40">
9:     <ContactInfo Email="baz@outlook.com" PhoneNo="789"/>
10:   </Profile>
11: </Profiles>
???????????????XML??????????????????????????????????????????????????????????????XML???????????????????????????????????????Key?????????XML????????????Dictionary<string?? Profile>??????Dictionary<int?? Profile>?????????????Key?????“0”??“1”??“2”??????????????????????????????????????????Dictionary<string?? Profile>????
1: <Profiles>
2:   <Foo Gender="Male" Age="18">
3:     <ContactInfo Email="foobar@outlook.com" PhoneNo="123"/>
4:   </Foo>
5:   <Bar Gender="Male" Age="25">
6:     <ContactInfo Email="foobar@outlook.com" PhoneNo="123"/>
7:   </Bar>
8:   <Baz Gender="Male" Age="18">
9:     <ContactInfo Email="baz@outlook.com" PhoneNo="789"/>
10:   </Baz>
11: </Profiles>
???????XML?????ConfigurationProvider?????XmlConfigurationProvider?????????????“Microsoft.Extensions.Configuration.Xml”??????????????NuGet??????????????????????ConfigurationProvider??????XmlConfigurationProvider??????JsonConfigurationProvider?????μ???塣?????????????????????????????????AddXmlFile????????????·?????????????XmlConfigurationProvider????????????????ConfigurationBuilder???????
1: public class XmlConfigurationProvider : ConfigurationProvider
2: {
3:     public XmlConfigurationProvider (string path);
4:     public XmlConfigurationProvider (string path?? bool optional);
5:
6:     public override void Load();
7:
8:     public string     Path { get; }
9:     public bool     Optional { get; }
10: }
11:
12: public static class XmlConfigurationExtensions
13: {
14:    public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder configurationBuilder?? string path);
15:    public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder configurationBuilder?? string path?? bool optional);
16: }
????????IniConfigurationProvider
????“INI”??“Initialization”????д??INI???????????????????????Windows????????????????????????ЩLinux??Unix????????INI???????????????????????????????????????????????INI?????????????????????INI??????????“{Key}={Value}”???????????????{Value}???????????????????У??????????????????????????????????????????????
????1: [Section]
????2: key1=value1
????3: key2 = " value2 "
????4: ; comment
????5: # comment
????6: / comment
??????????“{Key}={Value}”?????????????????????????????“[{SectionName}]”????????????y????????з??顣???????“[]”?????????????????y???????????????????????y????????????????INI???????????y?????????λ???????????“?????y?”????????????????????INI?ж???????????????????????????????“;”??“#”????“/”??
????????INI????????????????????????????????????“·????”??Key????????????????????????????????????????????INI????????????Profile???????????????????????????????????
????1: Gender              = "Male"
????2: Age                 = "18"
????3: ContactInfo:Email   = "foobar@outlook.com"
????4: ContactInfo:PhoneNo = "123456789"
??????Profile???????????????????Σ?Profile>ContactInfo?????????????????μ??????Emil??PhoneNo?????????y?“ContactInfo”?У????INI????????????????Ч???
????1: Gender  = "Male"
????2: Age     = "18"
????3:
????4: [ContactInfo]
????5: Email   = "foobar@outlook.com"
????6: PhoneNo = "123456789"
??????????INI?????ConfigurationProvider??IniConfigurationProvider????????????????NuGet????“Microsoft.Extensions.Configuration.Ini”?С???????????????????IniConfigurationProvider????????????????????ConfigurationProvider????????????ConfigurationBuilder?????????????IniConfigurationProvider?????????AddIniFile??
1: public class IniConfigurationProvider : ConfigurationProvider
2: {
3:     public IniConfigurationProvider (string path);
4:     public IniConfigurationProvider (string path?? bool optional);
5:
6:     public override void Load();
7:
8:     public string     Path { get; }
9:     public bool     Optional { get; }
10: }
11:
12: public static class IniConfigurationExtensions
13: {
14:    public static IConfigurationBuilder AddIniFile(this IConfigurationBuilder configurationBuilder?? string path);
15:    public static IConfigurationBuilder AddIniFile (this IConfigurationBuilder configurationBuilder?? string path?? bool optional);
16: }