12-optionBinding
1-创建一个空的dotnet mvc网站
2- 创建appsettings.json文件, 这文件会默认被绑定
{
"ClassNo": "1",
"ClassDesc": "Asp.net core",
"Students": [
{
"name": "lili",
"age": "11"
},
{
"name": "xiaofeng",
"age": "33"
},
{
"name": "xiaobao",
"age": "66"
}
]
}
3-创建一个可映射的class类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; namespace optionBindingDemo
{
public class Classes
{
public string ClassNo { get; set; } public string ClassDesc { get; set; } public List<Student> Students { get; set; }
} public class Student
{
public string Age { get; set; }
public string Name { get; set; }
}
}
4-开始绑定
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration; namespace optionBindingDemo
{
public class Startup
{
IConfiguration Configuration;
public Startup(IConfiguration configuration)
{
this.Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
Classes cls = new Classes();
this.Configuration.Bind(cls);
app.Run(async (context) =>
{
await context.Response.WriteAsync($"ClassNo: {cls.ClassNo}");
await context.Response.WriteAsync($"ClassDesc: {cls.ClassDesc}");
await context.Response.WriteAsync($"studentListCount: {cls.Students.Count}");
});
}
}
}
12-optionBinding的更多相关文章
- python 各模块
01 关于本书 02 代码约定 03 关于例子 04 如何联系我们 1 核心模块 11 介绍 111 内建函数和异常 112 操作系统接口模块 113 类型支持模块 114 正则表达式 115 语言支 ...
- Python Standard Library
Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...
- 在mybatis中写sql语句的一些体会
本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...
- AndroidStudio — Error:Failed to resolve: junit:junit:4.12错误解决
原博客:http://blog.csdn.net/u013443865/article/details/50243193 最近使用AndroidStudio出现以下问题: 解决:打开app下的buil ...
- 读过MBA的CEO更自私?《哈佛商业评论》2016年第12期。4星
老牌管理杂志.每期都值得精度.本期我还是给4星. 以下是本书中的一些内容的摘抄: 1:他们发现在Airbnb上,如果客人姓名听起来像黑人,那么比名字像白人的客人的接受率会低16%.#45 2:对立组织 ...
- 12个小技巧,让你高效使用Eclipse
集成开发环境(IDE)让应用开发更加容易.它们强调语法,让你知道是否你存在编译错误,在众多的其他事情中允许你单步调试代码.像所有的IDE一 样,Eclipse也有快捷键和小工具,这些会让您感觉轻松许多 ...
- 第12章 Linux系统管理
1. 进程管理 1.1 进程查看 (1)进程简介 进程是正在执行的一个程序或命令(如ls命令也是一个进程),每个进程都是一个运行的实体,都有自己的地址空间,并占用一定的系统资源. (2)进程管理的作用 ...
- Jexus Web Server 完全傻瓜化图文配置教程(基于Ubuntu 12.04.3 64位)[内含Hyper-v 2012虚拟机镜像下载地址]
1. 前言 近日有感许多新朋友想尝试使用Jexus,不过绝大多数都困惑徘徊在Linux如何安装啊,如何编译Mono啊,如何配置Jexus啊...等等基础问题,于是昨日向宇内流云兄提议,不如搞几个配置好 ...
- CSharpGL(12)用T4模板生成CSSL及其renderer代码
CSharpGL(12)用T4模板生成CSSL及其renderer代码 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码中包含10多个独立 ...
- ABP(现代ASP.NET样板开发框架)系列之12、ABP领域层——工作单元(Unit Of work)
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之12.ABP领域层——工作单元(Unit Of work) ABP是“ASP.NET Boilerplate Pr ...
随机推荐
- better-scroll 遇到的问题 3 (transition-group 相关)
今天在使用vue动画 transition-group 和 better-scroll 的时候,出现了下拉列表不能滚动的问题. 问题描述: 我写了一个scroll的基础组件,组件接受一个data参数, ...
- Struts2_Namespace
namespace 决定了action的访问路径,默认为"",可以接收所有路径的action,当精确的index.action处理不了的时候,就会找到这个action;namesp ...
- 腾讯云、CloudXNS域名服务器
腾讯云 f1g1ns1.dnspod.net f1g1ns2.dnspod.net CloudXNS lv3ns1.ffdns.net lv3ns2.ffdns.net lv3ns3.ffdns.ne ...
- leetcode:查找
1. word ladder 题目: Given two words (start and end), and a dictionary, find the length of shortest t ...
- 力不从心 Leetcode(ugly number heap) 263, 264,313
Leetcode ugly number set (3 now) new ugly number is generated by multiplying a prime with previous g ...
- IOS ScrollView的使用 and delegate
ScrollView常用的属性设置 //设置内容尺寸 // CGFloat contentH=self.lastBtn.frame // .origin.y+self.lastBtn.frame.si ...
- IOS 设置定时器,执行方法
//设置定时器(1秒后跳到一下题) [self performSelector:@selector(nextQuestion) withObject:nil afterDelay:1.0];
- linux命令之grep命令
grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正 ...
- CentOS 6\7修改主机名
1.CentOS6修改主机名 1)临时修改主机名: 显示主机名: oracle@localhost:~$ hostname localhost 修改 oracle@localhost:~$ sudo ...
- 2018.7.18 div,section,article的区别和使用
section ·<section> 标签定义文档中的节(section.区段).比如章节.页眉.页脚或文档中的其他部分. ·section用作一段有专题性的内容,一般在它里面会带有标题. ...