当前位置: 首页 > news >正文

jsp做门户网站网站如何申请微信支付接口

jsp做门户网站,网站如何申请微信支付接口,php网站开发接口文档,临沂展厅设计公司C# 10 新特性 —— CallerArgumentExpressionIntroC# 10 支持使用 CallerArgumentExpression 来自动地获取调用方的信息#xff0c;这可以简化我们现在的一些代码#xff0c;让代码更加简洁#xff0c;一起看下面的示例吧Caller InfoC# 在 5.0 的时候开始支持 Caller Info 自… C# 10 新特性 —— CallerArgumentExpressionIntroC# 10 支持使用 CallerArgumentExpression 来自动地获取调用方的信息这可以简化我们现在的一些代码让代码更加简洁一起看下面的示例吧Caller InfoC# 在 5.0 的时候开始支持 Caller Info 自动获取调用方的一些信息C# 5 开始支持的 Caller Info Attribute 有三个,[CallerMemberName] - 调用方成员名称方法名或者属性名.[CallerFilePath] - 调用方源代码所在文件路径[CallerLineNumber] - 调用方所在源代码的行数信息在方法参数中添加一个 Attribute 来获取调用方信息使用示例如下public static void MainTest() {// 我是谁我在哪儿DumpCallerInfo(); }private static void DumpCallerInfo([CallerFilePath] string? callerFilePath  null,[CallerLineNumber] int? callerLineNumber  null,[CallerMemberName] string? callerMemberName  null ) {Console.WriteLine(Caller info:);Console.WriteLine($CallerFilePath: {callerFilePath} CallerLineNumber: {callerLineNumber} CallerMemberName: {callerMemberName} ); }针对 CallerLineNumber 的类型是 int所以参数类型需要能够直接接收 int如上面的 [CallerLineNumber] int? callerLineNumber null 也可以改成 [CallerLineNumber] int callerLineNumber -1 或者 [CallerLineNumber] long callerLineNumber -1但是不能改成 [CallerLineNumber] string callerLineNumber null 或者 [CallerLineNumber] short callerLineNumber -1string 类型不兼容short 不能隐式转换上面代码输出结果类似下面Caller info: CallerFilePath: C:\projects\sources\SamplesInPractice\CSharp10Sample\CallerInfo.cs CallerLineNumber: 8 CallerMemberName: MainTestCallerArgumentExpressionCallerArgumentExpression 也是属于一种 Caller Info下面这里是利用 CallerArgumentExpression 实现的几个验证方法如果参数不合法就抛出一个异常通过 CallerArgumenExpression 来自动的获取调用方的参数表达式public static class Verify {public static void Argument(bool condition, string message, [CallerArgumentExpression(condition)] string? conditionExpression  null){if (!condition) throw new ArgumentException(message: message, paramName: conditionExpression);}public static void NotNullOrEmpty(string argument, [CallerArgumentExpression(argument)] string? argumentExpression  null){if (string.IsNullOrEmpty(argument)){throw new ArgumentException(Can not be null or empty, argumentExpression);}}public static void InRange(int argument, int low, int high,[CallerArgumentExpression(argument)] string? argumentExpression  null,[CallerArgumentExpression(low)] string? lowExpression  null,[CallerArgumentExpression(high)] string? highExpression  null){if (argument  low){throw new ArgumentOutOfRangeException(paramName: argumentExpression,message: ${argumentExpression} ({argument}) cannot be less than {lowExpression} ({low}).);}if (argument  high){throw new ArgumentOutOfRangeException(paramName: argumentExpression,message: ${argumentExpression} ({argument}) cannot be greater than {highExpression} ({high}).);}}public static void NotNullT(T? argument, [CallerArgumentExpression(argument)] string? argumentExpression  null)where T : class{ArgumentNullException.ThrowIfNull(argument, argumentExpression);} }来看一个使用调用示例var name  string.Empty; InvokeHelper.TryInvoke(()  Verify.NotNullOrEmpty(name));上面的 InvokeHelper.TryInvoke 是封装的一个方法如果有异常会记录一个日志上面代码执行结果如下可以看到我们的名称也是被记录了下来 Parameter 名字就是我们传入的变量名不需要我们再手动的额外加一个 nameof(name) 了再来看一个调用示例调用代码如下var num  10; InvokeHelper.TryInvoke(()  Verify.InRange(num, 2, 5)); InvokeHelper.TryInvoke(()  Verify.InRange(num, 10  2, 10  5));输出结果如下如果没有变量名或者属性名等就会直接用传入进来的 value 字面量如果传入进来的是一个表达式那么记录下来的就是表达式本身比如上面输出的 5/10 2而 num 是传入的一个变量就会获取到变量的名字是不是很神奇很多验证的地方就可以简化很多了SampleCallerArgumentExpression 有一个很典型的一个实际应用就是 .NET 6 里新增的一个 APIArgumentNullException.ThrowIfNull() 方法这个方法的实现如下/// summaryThrows an see crefArgumentNullException/ if paramref nameargument/ is null./summary /// param nameargumentThe reference type argument to validate as non-null./param /// param nameparamNameThe name of the parameter with which paramref nameargument/ corresponds./param public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(argument)] string? paramName  null) {if (argument is null){Throw(paramName);} }[DoesNotReturn] private static void Throw(string? paramName) throw new ArgumentNullException(paramName);源码可以从 Github 上看 https://github.com/dotnet/runtime/blob/v6.0.0/src/libraries/System.Private.CoreLib/src/System/ArgumentNullException.cs我们实际调用的时候就可以不传参数名会自动的获取参数名示例如下object? xiaoMing  null; InvokeHelper.TryInvoke(()  ArgumentNullException.ThrowIfNull(xiaoMing));输出结果如下从上面的结果我们可以看到参数名已经自动的解析出来了More升级 .NET 6 的小伙伴快用这个改造你的代码吧然后就是很多 null 检查也可以使用新的 ArgumentNullException.ThrowIfNull 去简化代码吧~~想使用上述代码测试可以从 Github 获取 https://github.com/WeihanLi/SamplesInPractice/blob/master/CSharp10Sample/CallerInfo.csReferenceshttps://www.codeproject.com/Tips/606379/Caller-Info-Attributes-in-Csharp-5-0https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/caller-argument-expression?WT.mc_idDT-MVP-5004222https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/caller-information?WT.mc_idDT-MVP-5004222https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-10?WT.mc_idDT-MVP-5004222#callerargumentexpression-attribute-diagnosticshttps://github.com/dotnet/runtime/blob/v6.0.0/src/libraries/System.Private.CoreLib/src/System/ArgumentNullException.cshttps://github.com/WeihanLi/SamplesInPractice/blob/master/CSharp10Sample/CallerInfo.cs
http://www.sadfv.cn/news/311344/

相关文章:

  • 网站备案密码重置app软件开发费用
  • 网站的服务器选择阿里巴巴吧网站怎么做
  • 创意手机网站线上推广活动方案
  • asp网站查看器扬中贴吧
  • 无锡网站优化推广方案wordpress显示注册用户
  • 网站建设怎么用长尾做标题网站建设如何使图片翻转
  • 商务网站建设与推广实训报告石家庄精准推广
  • 四川建设厅官方网站查询移动互联网开发学什么专业
  • 创建一个网站需要怎么做桂林做
  • 网站内链工作做足怎么通过建站来赚钱
  • 网站seo入门基础教程书籍建网站无锡
  • 顶呱呱网站建设是外包的吗济南 网站制作
  • 网站建网站建设设怎么在百度做原创视频网站
  • 四平市网站建设兰州市城市建设设计院
  • 佛山大良网站建设招聘网易搜索引擎
  • esp8266做网站大学网站建设的目标
  • 广州企业网站哪家好专业公司网站建设服务公司
  • 爱星光(istar)高端网站建设刚注册的域名卖了100万
  • 高端网站鉴赏百度爱采购推广一个月多少钱
  • 无锡新吴区建设环保局网站汉化插件wordpress
  • 免费设计商标的网站设计素材图片大全
  • 网站ssl证书怎么做网站空间报价单
  • 网站建设套餐做t恤网站 一件也可以做
  • 响应式网站模仿网站没有经过我司审核通过白名单
  • 绩溪做网站商业网站开发设计报告
  • 无锡新区规划建设环保局网站山西建站管理系统开发
  • 获取网站访问者qq号网页素材网站有哪些
  • 佛山高端网站建设报价宁波网站制作价格
  • 做赌场网站代理家私公司网站建设多少钱
  • 网站模板是什么意思怎么优化WordPress主题