net core 代码实践

Microsoft.extensions.configuration.Ini
Microsoft.extensions.configuration.Json
Microsoft.extensions.configuration.NewtonsoftJson
Microsoft.extensions.configuration.Xml
Microsoft.extensions.configuration.UserSecrets
IConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddJsonFile(System.AppDomain.CurrentDomain.BaseDirectory + "/appsettings.json");
var configurationRoot = builder.Build();
Console.WriteLine(configurationRoot["key1"]);
Console.WriteLine(configurationRoot["key2"]);
IConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddJsonFile(System.AppDomain.CurrentDomain.BaseDirectory + "/appsettings.json");
builder.AddJsonFile(System.AppDomain.CurrentDomain.BaseDirectory + "/appsettings_dev.json");
var configurationRoot = builder.Build();
Console.WriteLine(configurationRoot["key1"]);
Console.WriteLine(configurationRoot["key2"]);
IConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddJsonFile(System.AppDomain.CurrentDomain.BaseDirectory + "/appsettings.json",optional:false,reloadOnChange: true);
var configurationRoot = builder.Build();
Console.WriteLine(configurationRoot["key1"]);
Console.WriteLine(configurationRoot["key2"]);
Console.ReadKey();
Console.WriteLine(configurationRoot["key1"]);
Console.WriteLine(configurationRoot["key2"]);
Console.ReadKey();
public string this[string key]
{
get
{
for (int i = _providers.Count - 1; i >= 0; i--)
{
IConfigurationProvider provider = _providers[i];

if (provider.TryGet(key, out string value))
{
return value;
}
}

return null;
}
set
{
if (!_providers.Any())
{
throw new InvalidOperationException(SR.Error_NoSources);
}

foreach (IConfigurationProvider provider in _providers)
{
provider.Set(key, value);

上一篇:二层网络故障问题分享(1)


下一篇:matlab画GIS地图