ASP.NET Core???????3???? ?????e??????[???]
???????????? ???????[ 2016/6/7 14:47:45 ] ????????ASP.NET Core ???ù???
????xxx???????????????????????????????Profile?????????????????????????????????????????綽????????????????????????м??ɡ?????????????????????????У???????????????????????????????????????·????????????Key??
?????????????????????????????????????e?????????????ASP .NET Core?????????У?????project.json???????????NuGet??“Microsoft.Extensions.Configuration.Binder”?????????????????????????Main?????ж?????????????????
1: public class Program
2: {
3: public static void Main(string[] args)
4: {
5: IConfiguration configuration = new ConfigurationBuilder().Add(new MemoryConfigurationProvider(new Dictionary<string?? string>
6: {
7: ["Profile:Gender"] = "Male"??
8: ["Profile:Age"] = "18"??
9: ["Profile:ContactInfo:Email"] = "foobar@outlook.com"??
10: ["Profile:ContactInfo:PhoneNo"]= "123456789"??
11: })).Build();
12:
13: Profile profile = configuration.Get<Profile>("Profile");
14: Console.WriteLine("{0??-10}:{1}"?? "Gender"?? profile.Gender);
15: Console.WriteLine("{0??-10}:{1}"?? "Age"?? profile.Age);
16: Console.WriteLine("{0??-10}:{1}"?? "Email"?? profile.ContactInfo.Email);
17: Console.WriteLine("{0??-10}:{1}"?? "PhoneNo"?? profile.ContactInfo.PhoneNo);
18: }
19: }
??????????????????????????????????ConfigurationBuilder??????????????MemoryConfigurationProvider????????????2??????????????????????????????????ConfigurationBuilder????????Configuration???????????ConfigurationSection??Get??????Key?“Profile”?????y??????Profile?????????????e??????????????????????Profile?????????????????????ó??????????????????????????????????????
????1: Gender :Male
????2: Age :18
????3: Email :foobar@outlook.com
????4: PhoneNo :123456789
????????????????
???????e?????????????????????????????????????????????????????????????????????????????????????????????????????????????e????????????????????????????????????????????????????????????????????????????????????????????????????????Profile??????????????????????????????
??????????8????????????????????????????????????????????????????????????y??????“Profile”???Key??????????????????·??????????????·?????????????????????????????????Key???????????????????????????????????????????????????????????????????????????????0??1??2?? …??????????y??Key????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????е???????????????????е??????????????·???????????????Key?? ?????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11