ASP.NET Core???????1??????????????
???????????? ???????[ 2016/5/27 10:55:44 ] ?????????????????? ???ù???
??????“????”??????????????.NET???????????л??????????????????????????????????????????????app.config??web.config?????????????????????????????????????????????????????С?????.NET Core????????????????????????????????????????????????????????????????μ???????????????????????????и???????????????????????????????????????????????????????????????????????????????????????????????????????С?
???????????????????????????????????????????????????????????й????????????????????????????????顣????????API?漰????????????????Configuration??ConfigurationBuilder??ConfigurationProvider??????????о????????????????????????????????????????????Configuration???????????????????????????????ConfigurationProvider???????????????????????????????乵???ConfigurationBuilder????????????ConfigurationProvider???????????????Configuration????
??????????-??????????????
????????????????μ?????????????????????????????????ι????????“???”???????????“??-???”?????????????????????????????????????????????????????????????????????????????????á??????????????ASP.NET Core??????????????project.json?а??????μ?????????“Microsoft.Extensions.Configuration”???NuGet????????????????????????????С?
????1: {
????2: ...
????3: "dependencies": {
????4: "Microsoft.Extensions.Configuration": "1.0.0-rc1-final"
????5: }??
????6: }
?????????????????????????????趨????/???????????????????????????????DateTimeFormatSettings???????????????????DateTime???????????????????????????/?????????/?????
????1: public class DateTimeFormatSettings
????2: {
????3: public string LongDatePattern { get; set; }
????4: public string LongTimePattern { get; set; }
????5: public string ShortDatePattern { get; set; }
????6: public string ShortTimePattern { get; set; }
????7: //???????
????8: }
??????????????????????????????DateTimeFormatSettings??????????????????/??????????????????????????????????????????????????????????ù????????????IConfiguration??????????????????????????????????Configuration???????????Configuration????????????????????????Key???????Value??
????1: public class DateTimeFormatSettings
????2: {
????3: //???????
????4: public DateTimeFormatSettings (IConfiguration configuration)
????5: {
????6: this.LongDatePattern = configuration["LongDatePattern"];
????7: this.LongTimePattern = configuration["LongTimePattern"];
????8: this.ShortDatePattern = configuration["ShortDatePattern"];
????9: this.ShortTimePattern = configuration["ShortTimePattern"];
????10: }
????11: }
???????????????????????DateTimeFormatSettings??????????????????????????????????Configuration?????????????????????Configuration????????ConfigurationBuilder????????????????????????????????ConfigurationProvider??????????????????Configuration???????????????????????ConfigurationBuilder?????????????????????ConfigurationProvider??????????ConfigurationBuilder???????????????Configuration????
??????????????????????????????????????б?д?????μ?????????????????????ConfigurationBuilder???????????Add????????ConfigurationProvider??????????MemoryConfigurationProvider???????????壬MemoryConfigurationProvider????????е??????????????????????????????Щ????????????????????????????KeyValuePair<string?? string>???????С??????????ConfigurationBuilder??Build??????????????DateTimeFormatSettings?????????Configuration??
1: public class Program
2: {
3: public static void Main(string[] args)
4: {
5: Dictionary<string?? string> source = new Dictionary<string?? string>
6: {
7: ["LongDatePattern"] = "dddd?? MMMM d?? yyyy"??
8: ["LongTimePattern"] = "h:mm:ss tt"??
9: ["ShortDatePattern"] = "M/d/yyyy"??
10: ["ShortTimePattern"] = "h:mm tt"
11: };
12: IConfiguration configuration = new ConfigurationBuilder()
13: .Add(new MemoryConfigurationProvider(source))
14: .Build();
15:
16: DateTimeFormatSettings settings = new DateTimeFormatSettings(configuration);
17: Console.WriteLine("{0??-16}: {1}"?? "LongDatePattern"?? settings.LongDatePattern);
18: Console.WriteLine("{0??-16}: {1}"?? "LongTimePattern"?? settings.LongTimePattern);
19: Console.WriteLine("{0??-16}: {1}"?? "ShortDatePattern"?? settings.ShortDatePattern);
20: Console.WriteLine("{0??-16}: {1}"?? "ShortTimePattern"?? settings.ShortTimePattern);
21: }
22: }
???????????????????????DateTimeFormatSettings??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????1: LongDatePattern : dddd?? MMMM d?? yyyy
????2: LongTimePattern : h:mm:ss tt
????3: ShortDatePattern: M/d/yyyy
????4: ShortTimePattern: h:mm tt
???????? ?????????????
?????????????漰?????????????????????ν?????????????????е?Configuration?????????????????????????????t?????????β?ν????????Configuration????????????????????????????????????????????????????????Configuration???????????????????????????????????????????????????Configuration?????У?????????Configuration????????????????????????????Configuration????
?????????????????????????????????ζ??岢??????в?λ????????á????????????????????ó?????????????????????????????/?????????????????????????????????????????????Decimal????????????????????????CurrencyDecimalFormatSettings??????????Digits??Symbol?????С??λ??????????????CurrencyDecimalFormatSettings????????????????????????Configuration?????????????
????1: {
????2: public int Digits { get; set; }
????3: public string Symbol { get; set; }
????4:
????5: public CurrencyDecimalFormatSettings(IConfiguration configuration)
????6: {
????7: this.Digits = int.Parse(configuration["Digits"]);
????8: this.Symbol = configuration["Symbol"];
????9: }
????10: }
??????
???·???
??????????????????
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