博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.NET Core 配置
阅读量:6994 次
发布时间:2019-06-27

本文共 1759 字,大约阅读时间需要 5 分钟。

下面的代码演示了如何在.NET Core中使用“内存配置”:

///     /// 获取格式设置    ///     /// 
public static FormatSettings GetFormatSettings() { // Key使用冒号:分隔路径,实现层级化 Dictionary
initialData = new Dictionary
{ // 时间格式化 ["Format:DateTime:LongDatePattern"] = "dddd, MMMM d, yyyy", ["Format:DateTime:LongTimePattern"] = "h:mm:ss tt", ["Format:DateTime:ShortDatePattern"] = "M/d/yyyy", ["Format:DateTime:ShortTimePattern"] = "h:mm tt", // 金额格式化 ["Format:CurrencyDecimal:Digits"] = "2", ["Format:CurrencyDecimal:Symbol"] = "$", }; var source = new MemoryConfigurationSource { InitialData = initialData }; IConfiguration configuration = new ConfigurationBuilder() .Add(source) .Build().GetSection("Format"); IOptions
optionsAccessor = new ServiceCollection() .AddOptions() .Configure
(configuration) .BuildServiceProvider() .GetService
>(); FormatSettings settings = optionsAccessor.Value; return settings; } ///
/// 格式设置类 /// public class FormatSettings { public DateTimeFormatSettings DateTime { get; set; } public CurrencyDecimalFormatSettings CurrencyDecimal { get; set; } } ///
/// 时间格式化设置 /// public class DateTimeFormatSettings { public string LongDatePattern { get; set; } public string LongTimePattern { get; set; } public string ShortDatePattern { get; set; } public string ShortTimePattern { get; set; } } ///
/// 货币格式化设置 /// public class CurrencyDecimalFormatSettings { public int Digits { get; set; } public string Symbol { get; set; } }

 

转载于:https://www.cnblogs.com/WinHEC/p/9289841.html

你可能感兴趣的文章
MyBatis 之 延迟加载(Lazy Load)
查看>>
Disruptor剖析
查看>>
oracle数据仓库物理模型设计
查看>>
Squid三种代理方式的实现及ACL
查看>>
在透视表中定义公式
查看>>
我的友情链接
查看>>
close_wait状态的产生原因及解决(1)
查看>>
堆(heap)
查看>>
Windows Server 2016-图形化之客户端加域(一)
查看>>
Silverlight 版 C1OutlookBar 初体验
查看>>
使用Visual Studio 2012 开发 Html5 应用
查看>>
通过案例学调优之--Oracle 全文索引
查看>>
Java自带的性能监测工具之jstat
查看>>
HBase Shell 基本操作
查看>>
samba
查看>>
网站制作的注意事项
查看>>
Exchange会议室的应用之Redis内存数据库
查看>>
浅谈分布式并发控制
查看>>
C#高级编程之委托
查看>>
2018.12.7python笔记(3.3-3.5)
查看>>