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

湖南网站设计方案网站竞争对手

湖南网站设计方案,网站竞争对手,建站公司一般怎么获客,网站名称如何设置NET Core的AOP实施方法1 DispatchProxy NET Framework的AOP实施方法1 ContextBoundObject NET Framework的AOP实施方法2 RealProxy 源码见Github DispatchProxy NET Core DispatchProxy 是一个在 .NET 框架中引入的概念#xff0c;特别是在 C# 语言中。它是一种特殊类型的代…NET Core的AOP实施方法1 DispatchProxy NET Framework的AOP实施方法1 ContextBoundObject NET Framework的AOP实施方法2 RealProxy 源码见Github DispatchProxy NET Core DispatchProxy 是一个在 .NET 框架中引入的概念特别是在 C# 语言中。它是一种特殊类型的代理用于在运行时动态地分派方法调用到不同的实现。DispatchProxy 类位于 System.Runtime.Remoting.Proxies 命名空间中并且是 RealProxy 类的一个派生类。 以下是 DispatchProxy 的一些关键点 动态分派DispatchProxy 允许开发者在运行时决定将方法调用分派给哪个对象。这使得可以在不修改现有代码的情况下动态地改变对象的行为。 透明代理DispatchProxy 是一种透明代理这意味着客户端代码不需要知道代理的存在。客户端代码可以直接调用方法就像它们直接调用实际对象一样。 类型安全尽管 DispatchProxy 是动态分派的但它仍然保持类型安全。代理对象可以被强制转换为任何接口类型并且只有那些接口上的方法调用才会被分派。 创建自定义代理开发者可以通过继承 DispatchProxy 类并重写 Invoke 方法来创建自己的代理。在 Invoke 方法中开发者可以决定如何分派方法调用例如基于调用的方法名、参数或其他逻辑。 性能开销由于 DispatchProxy 涉及到运行时的动态分派因此可能会有一些性能开销。因此它更适合于那些性能不是主要关注点的场景。 用途DispatchProxy 可以用于多种场景包括但不限于日志记录、性能监控、事务管理、安全性检查、Mock对象的创建等。 相较于RealProxy和ContextBoundObjectDispatchProxy的实现更加便捷 创建日志拦截器 public class LoggingDecoratorT : DispatchProxy {private T _decorated;protected override object Invoke(MethodInfo methodInfo, object[] args){try{LogBefore(methodInfo, args);var result methodInfo.Invoke(_decorated, args);if (methodInfo.IsAsyncMethod()){if (methodInfo.ReturnType typeof(Task)){var task (Task)result;var val InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(task,async () {Debug.WriteLine($Task {methodInfo.Name} completed);}, /*成功时执行*/ex {if (ex ! null){Debug.WriteLine($Task {methodInfo.Name} threw an exception: {ex.ToString()});}});return val;}else{var returnTypeGenericTypeArgument methodInfo.ReturnType.GenericTypeArguments[0];var val InternalAsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult(returnTypeGenericTypeArgument,result,async (o) {Debug.WriteLine($Task {methodInfo.Name} completed with result {o});}, /*成功时执行*/ex {if (ex ! null){Debug.WriteLine($Task {methodInfo.Name} threw an exception: {ex.ToString()});}});return val;}}else{LogAfter(methodInfo, args, result);}return result;}catch (Exception ex) when (ex is TargetInvocationException){LogException(ex.InnerException ?? ex, methodInfo);throw ex.InnerException ?? ex;}}public static T Create(T decorated){object proxy CreateT, LoggingDecoratorT();((LoggingDecoratorT)proxy).SetParameters(decorated);return (T)proxy;}private void SetParameters(T decorated){if (decorated null){throw new ArgumentNullException(nameof(decorated));}_decorated decorated;}private void LogException(Exception exception, MethodInfo methodInfo null){Console.WriteLine($Class {_decorated.GetType().FullName}, Method {methodInfo.Name} threw exception:\n{exception});}private void LogAfter(MethodInfo methodInfo, object[] args, object result){Console.WriteLine($Class {_decorated.GetType().FullName}, Method {methodInfo.Name} executed, Output: {result});}private void LogBefore(MethodInfo methodInfo, object[] args){Console.WriteLine($Class {_decorated.GetType().FullName}, Method {methodInfo.Name} is executing);} }代理异步的帮助类 internal static class InternalAsyncHelper {public static bool IsAsyncMethod(this MethodInfo method){return method.ReturnType typeof(Task)|| method.ReturnType.IsGenericType method.ReturnType.GetGenericTypeDefinition() typeof(Task);}public static async Task AwaitTaskWithPostActionAndFinally(Task actualReturnValue,FuncTask postAction,ActionException finalAction){Exception exception null;try{await actualReturnValue;await postAction();}catch (Exception ex){exception ex;}finally{finalAction(exception);}}public static async TaskT AwaitTaskWithPostActionAndFinallyAndGetResultT(TaskT actualReturnValue,Funcobject, Task postAction,ActionException finalAction){Exception exception null;try{var result await actualReturnValue;await postAction(result);return result;}catch (Exception ex){exception ex;throw;}finally{finalAction(exception);}}public static object CallAwaitTaskWithPostActionAndFinallyAndGetResult(Type taskReturnType,object actualReturnValue,Funcobject, Task action,ActionException finalAction){//AwaitTaskWithPostActionAndFinallyAndGetResulttaskReturnType(actualReturnValue, action, finalAction);return typeof(InternalAsyncHelper).GetMethod(AwaitTaskWithPostActionAndFinallyAndGetResult,BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(taskReturnType).Invoke(null, new object[] { actualReturnValue, action, finalAction });} }声明及调用示例 public interface ICalculator {int Add(int a, int b);Taskint AddAsync(int a, int b); } public class Calculator : ICalculator {public int Add(int a, int b){//throw new NotImplementedException(This method is not implemented. sorry!);return a b;}public async Taskint AddAsync(int a, int b){await Task.Delay(1000);return a b;} }示例 var decoratedCalculator LoggingDecoratorICalculator.Create(new Calculator()); decoratedCalculator.Add(3, 5); Console.WriteLine($Started at {DateTime.Now:HH:mm:ss.fff}); var res decoratedCalculator.AddAsync(2, 4);Console.WriteLine(Waiting for 1 seconds for querying customer...); Console.WriteLine($Querying {DateTime.Now:HH:mm:ss.fff}); Console.WriteLine(res.GetAwaiter().GetResult()); Console.WriteLine($Finished at {DateTime.Now:HH:mm:ss.fff});
http://www.hkea.cn/news/14482312/

相关文章:

  • 用vs网站开发网站开发需要用到哪些设备
  • 外网常用网站wordpress wp大学
  • 成都建站模板网站开发程序
  • 海天网站建设资讯门户类网站
  • 冻品网站的建设背景广东省app开发公司
  • app ui设计欣赏 网站哪种语言的网站 做seo更好
  • 商务网站开发与建设网页对于网站有多重要
  • 东莞seo网站排名淘宝联盟怎么建网站
  • 网站logo重庆网站建设yunhuit
  • php做的网站后台长沙有啥好玩的地方
  • 可以做头像的网站十大网络科技公司
  • 农业公司网站源码做网站有视频教吗
  • 营销型网站的目标是怎样在在农行网站上做风险评估
  • 内蒙网站建设赫伟创意星空科技苏州小程序开发哪家好
  • 做a手机视频在线观看网站网站源码中国有限公司
  • 做淘宝客网站好搭建吗?国内外免费域名解析网站
  • 网站建设备案和免备案的区别健康生活网站开发系统背景
  • 网站怎么做数据转移残联网站建设方案
  • 那位学生网站开发wordpress 爆破脚本
  • 怎么自己做彩票网站吗网站发稿平台
  • 自己做国外网站建网站平台哪家好
  • 为网站 做字幕wordpress标签关键词
  • 自适应 网站开发为什么很多中国人去菲律宾做网站
  • 手机网站制作流程图项目推广方式有哪些
  • 建设旅游网站的目的和意义wordpress搜索增强
  • 做金融必看网站建设工程安全信息网
  • 怎样健网站旅游网页代码模板
  • php网站开发前端新乡网站建设服务哪家好
  • 湖南太平洋建设集团网站专业网站开发制作
  • 商城网站建设解决方案创建购物平台需要什么