Asp.net core 学习笔记 ( 小东西 )
简单的为 url 添加 query
var parametersToAdd = new System.Collections.Generic.Dictionary<string, string> { { "resource", "foo" } }; var someUrl = "http://www.google.com"; var newUri = Microsoft.AspNetCore.WebUtilities.QueryHelpers.AddQueryString(someUrl, parametersToAdd);
判断类
判断 1 个 class 准准是某个 class
resourceContext.ResourceInstance.GetType() == typeof(User);
判断 1 个 class 是不是某个 class 的 child ( must be child, parent must be class, interface can't )
resourceContext.ResourceInstance.GetType().IsSubclassOf(typeof(IdentityUser<int>)); // child -> parent
判断 1 个 class 是不是某个 interface or class 或则它的 child
typeof(User).IsAssignableFrom(resourceContext.ResourceInstance.GetType()); // parent -> child
判断 1 个 object 是不是某个 interface or class 或则它的 child , 和上一个是一样的逻辑,只是这个是 object
typeof(IEntity).IsInstanceOfType(resourceContext.ResourceInstance);
resourceContext.ResourceInstance is IEntity; // is 也就是这个意思