zoukankan      html  css  js  c++  java
  • .net core Configuration的 索引器的隐藏技能

    ...

    namespace Test20190417.Mvc {
    public class Startup {
    public Startup(IConfiguration configuration) {
    Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services) {
    services.Configure<CookiePolicyOptions>(options => {
    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
    options.CheckConsentNeeded = context => true;
    options.MinimumSameSitePolicy = SameSiteMode.None;
    });
    System.Console.WriteLine(this.Configuration["dbcon"]);
    System.Console.WriteLine(this.Configuration["a:b:c:d:1"]);
    System.Console.WriteLine(this.Configuration["a:b2:c2:e:0:e2"]);
    services.AddDbContext<selfmanagementdb>(op => op.UseSqlite(this.Configuration["dbcon"]));
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    }

    ...

    appsettings.json 文件内容如下:

    {
    "Logging": {
    "LogLevel": {
    "Default": "Warning"
    }
    },
    "AllowedHosts": "*",
    "dbcon": "Data Source=mydb.db;Version=3;",
    "a": {
    "b": {
    "c": { "d": [ 1, 2, 3 ] }
    },
    "b2": {
    "c": {
    "d": [ 4, 5, 6 ],
    "d2": [ 7, 8, 9 ]
    },
    "c2": {
    "d": [ 1, 3, 5 ],
    "e": [
    {
    "e1": true,
    "e2": "aaa"
    },
    {
    "e1": true,
    "e2": "aaa"
    }
    ]
    }
    }
    }
    }

    ------------------------------------------------结果:

    Data Source=mydb.db;Version=3;
    2
    aaa

    任何复杂 的json结构 都可以通过 这种简单的字符串表达规则找到,非常方便!

  • 相关阅读:
    php单引号和双引号
    转CSS技巧大全
    在C#中实现打印功能(C#中PrintDialog,PrintDocument的使用) (转)
    从安装到使用Ubuntu遇到问题解决问题一览
    原型模型
    PHP源代码分析 tick(s)
    在DOS下修改windows 登入密码 转载
    配置php5.3.6+Apache2.2
    Java多线程全源码分析
    本笨鸟今天开始学习.net,有木有一起开始学的
  • 原文地址:https://www.cnblogs.com/ProjectDD/p/10748015.html
Copyright © 2011-2022 走看看