美国当地时间12月4日,微软2019开发者大会中发布了一系列的重磅消息,包含了软硬件和开源社区的各种好消息是铺天盖地,作为一名普通的开发者,我第一时间下载了 .net core 2.2 的源码,针对发布说明逐条浏览,并截取了部分常用的功能进行尝试,下面就与大家分享。
[httpget] public actionresult<userinfo> get() { return new userinfo() { name = "ron.liang", regtime = datetime.now }; } [httpget("{id}")] public actionresult<dictionary<string, string>> get(int id) { return new dictionary<string, string> { { "name", "ron.liang" }, { "regtime", datetime.now.tostring() } }; } // 接口 1 输出 { name: "ron.liang", regtime: "2018-12-05t10:40:37.5090634+08:00" } // 接口 2 输出 { name: "ron.liang", regtime: "2018-12-05t10:40:58.5072645+08:00" }
public void configureservices(iservicecollection services) { services.addmvc().addjsonoptions(o => o.usecamelcasing(false)).setcompatibilityversion(compatibilityversion.version_2_2); }
addjsonoptions 内置两个默认扩展,你可以使用 usecamelcasing 或者 usemembercasing ,如果使用 usemembercasing ,表示使用成员字段的大小写规则,即不改变大小写输出
1.3 有意思的是,addjsonoptions(o => o.usecamelcasing(true)) 显式传入值的方式是由 jamesnk 这个哥们杠出来的结果,详见
https://github.com/aspnet/mvc/pull/7962
public class userinfo { [stringlength(20), regularexpression(@"^[a-za-z]$")] public string name { get; set; } [stringlength(20), regularexpression(@"^[a-za-z]$")] public string title { get; set; } public datetime regtime { get; set; } }
public class userinfo { [name] public string name { get; set; } [name] public string title { get; set; } public datetime regtime { get; set; } } public class nameattribute : validationproviderattribute { public override ienumerable<validationattribute> getvalidationattributes() { return new list<validationattribute> { new requiredattribute(), new regularexpressionattribute(pattern: "[a-za-z]*"), new stringlengthattribute(maximumlength: 20) }; } }
namespace microsoft.aspnetcore.mvc { /// <summary> /// a filter that specifies the type of the value and status code returned by the action. /// </summary> [attributeusage(attributetargets.class | attributetargets.method, allowmultiple = true, inherited = true)] public class producesresponsetypeattribute : attribute, iapiresponsemetadataprovider { .... }
//旧的: @html.partial("_statusmessage", model.statusmessage) // 新的: <partial name="_statusmessage", for="statusmessage" />
如对本文有疑问, 点击进行留言回复!!
mysql中如何实现 row_number分组求topN的功能
SQLSERVER中RANK OVER(PARTITION BY)的用法
Kaspersky Endpoint Security 10 for Windows version 10.2.6.3733 is no longer supported
网友评论