public class AppSettings
{
IConfiguration config;
public AppSettings():this("appsettings.json") { }
public AppSettings(string jsonFileName)
{
var configBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(jsonFileName);
config = configBuilder.Build();
}
public string this[string name]
{
get { return config.GetSection(name).Value;}
}
}
用法
AppSettings get = new AppSettings();
string v = get["key"];