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结构 都可以通过 这种简单的字符串表达规则找到,非常方便!

  • 相关阅读:
    使用jsonp跨域调用百度js实现搜索框智能提示(转)
    jsonp 跨域
    Aixs2发布webservice服务
    java web service 上传下载文件
    java 网页 保存上传文件
    flash、js 函数 互相调用
    java web工程启动socket服务
    mysql 在Windows下自动备份
    Servlet中几个常用方法的推衍
    Tomcat常用设置 <持续更新>
  • 原文地址:https://www.cnblogs.com/ProjectDD/p/10748015.html
Copyright © 2011-2022 走看看