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

公司网站平台现在做电商哪个平台好

公司网站平台,现在做电商哪个平台好,网站建设怎么分类,网站demo制作工具前言最近在公众号上看到一篇文章《究竟是什么可以比反射还快实现动态调用#xff1f;》#xff0c;它使用的是Newbe.ObjectVisitor#xff0c;基于C#表达式树访问一个普通class的所有属性和对应的值#xff0c;可以拥有比直接使用反射快上10倍的性能。就这一需求来说#… 前言最近在公众号上看到一篇文章《究竟是什么可以比反射还快实现动态调用》它使用的是Newbe.ObjectVisitor基于C#表达式树访问一个普通class的所有属性和对应的值可以拥有比直接使用反射快上10倍的性能。就这一需求来说我认为Source Generators应该会更快因为访问代码在编译时而不是运行时就生成了。事实也验证了确实如此实现这次我们使用第三方开发的Source Generators类库来实现。1.引用Nuget包创建示例控制台程序引用如下Nuget包AOPMethodsCommon AOPMethodsGenerator2.设置Attribute在需要动态调用的类上声明Attribute[AutoMethods(template  TemplateMethod.CustomTemplateFile, CustomTemplateFileName  template.txt)] public class Yueluo3.代码模板添加template.txt用在Source Generators生成动态调用代码的模板.内容如下using System; using System.Collections.Generic; using System.CodeDom.Compiler; using System.Runtime.CompilerServices; namespace {{NamespaceName}} {public static class {{ClassName}}Extentions{public static string ValueStringProperty(this {{ClassName}} obj, string val){{{~ for mi in Properties ~}}{{~ if( mi.ReturnType   string ) ~}}if(string.Compare({{mi.Name}},val,StringComparison.CurrentCultureIgnoreCase)0) {return obj.{{mi.Name}};}{{~ end ~}}{{~ end ~}}throw new ArgumentException(cannot find  val);}public static int ValueIntProperty(this {{ClassName}} obj, string val){{{~ for mi in Properties ~}}{{~ if( mi.ReturnType   int ) ~}}if(string.Compare({{mi.Name}},val,StringComparison.CurrentCultureIgnoreCase)0) {return obj.{{mi.Name}};}{{~ end ~}}{{~ end ~}}throw new ArgumentException(cannot find  val);}public static object ValueProperty(this {{ClassName}} obj, string val){{{~ for mi in Properties ~}}if(string.Compare({{mi.Name}},val,StringComparison.CurrentCultureIgnoreCase)0) {return obj.{{mi.Name}};}{{~ end ~}}throw new ArgumentException(cannot find  val);}} }模板使用了scriban进行解析具体语法详见https://github.com/scriban/scriban/blob/master/doc/language.md以ValueStringProperty方法举例来说public static string ValueStringProperty(this {{ClassName}} obj, string val){{{~ for mi in Properties ~}}{{~ if( mi.ReturnType   string ) ~}}if(string.Compare({{mi.Name}},val,StringComparison.CurrentCultureIgnoreCase)0) {return obj.{{mi.Name}};}{{~ end ~}}{{~ end ~}}throw new ArgumentException(cannot find  val); }遍历类的所有属性Properties判断当前属性返回类型mi.ReturnType是string则返回对应属性名的值。4.使用下面是Benchmark测试代码分别使用了Newbe.ObjectVisitor和Source Generators[Benchmark] public string GetterString() ValueGetterYueluo, string, string.GetGetter(_nameProperty).Invoke(_yueluo);[Benchmark] public int GetterInt() ValueGetterYueluo, int, int.GetGetter(_ageProperty).Invoke(_yueluo);[Benchmark] public string GetterString2() { return _yueluo.ValueStringProperty(Name);  }[Benchmark] public int GetterInt2() {return  _yueluo.ValueIntProperty(Age); }可以看到Source Generators生成的代码可读性更高。结论对于编译时可生成的功能尽量使用Source Generators实现可以达到更好的性能和可读性。如果你觉得这篇文章对你有所启发请关注我的个人公众号”My IO“
http://www.pierceye.com/news/39135/

相关文章:

  • 铜陵市建设局网站有什么设计网站推荐
  • 鹤壁网站建设杭州做购物网站
  • 佛山正规的免费网站优化wordpress打开空白
  • 网站开发的需求分析论文营销型网站建设价格贵吗
  • 网站优化培训机构网站开发需要学shenme
  • 互联网营销案例seo优化的主要任务包括
  • 免费制作封面网站微信商城小程序平台
  • 范县网站建设价格创意营销策划案例
  • 学校网站在哪里找网络服务类型及其采用的网络协议有哪些
  • 如何做网站的教程河南省城市建设网站
  • 网站开发与网站制作贵安新区网站建设推广
  • jsp编写网站网站建设网站制作需要多少钱
  • 做我的奴隶 good网站最好的wordpress
  • 张家界商城网站建设网站类网站建设
  • 湘潭网站建设 搜搜磐石网络.net个人网站开发视频
  • 崔各庄地区网站建设临沂国际外贸网站建设
  • 做公司网站麻烦吗做电影网站需要什么软件
  • 自己做的网站怎么发布做百度推广得用网站是吗
  • 网站5g空间python 网站开发 普及
  • 优秀材料写作网站东莞寮步网站设计
  • 制作网页类型一般分为什么沈阳做网站seo
  • 备案个人网站做淘宝客招聘模板图片
  • 网站服务器买了后怎么做的wordpress同步头条
  • 凡科建站登录入口在线制作网站源码
  • 红安建设局网站免费h5制作软件
  • 滁州市建设工程质量检测协会网站使用element做的网站
  • 东营做网站优化的公司汕头百度关键词优化
  • 岱山建设局网站办公室装修图
  • 最新网站开发需求文档织梦免费企业网站
  • 杭州做企业网站公司建设企业网站源码