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 也就是这个意思

 

posted @   兴杰  阅读(171)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 百万级群聊的设计实践
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
点击右上角即可分享
微信分享提示