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

电子简历表格手机版武汉seo技术

电子简历表格手机版,武汉seo技术,营销网站有哪些,建设网站坂田首先&#xff0c;我们需要定义一个接口&#xff0c;代表我们要代理的目标对象的功能&#xff1a; // 日志记录器接口 public interface ILogger {/// <summary>/// 记录日志/// </summary>/// <param name"message">日志消息</param>void L…

首先,我们需要定义一个接口,代表我们要代理的目标对象的功能:

// 日志记录器接口
public interface ILogger
{/// <summary>/// 记录日志/// </summary>/// <param name="message">日志消息</param>void Log(string message);
}// 日志记录器实现类
public class Logger : ILogger
{public void Log(string message){Console.WriteLine($"Logging: {message}");}
}

然后,我们创建一个代理类,实现该接口,并在目标方法的执行前后注入额外的逻辑:

// 切面接口
public interface IInterceptor
{/// <summary>/// 在方法执行前执行的逻辑/// </summary>/// <param name="targetType">目标类型</param>/// <param name="methodName">方法名称</param>void BeforeMethod(Type targetType, string methodName);/// <summary>/// 在方法执行后执行的逻辑/// </summary>/// <param name="targetType">目标类型</param>/// <param name="methodName">方法名称</param>void AfterMethod(Type targetType, string methodName);
}// 日志记录切面类
public class LoggingAspect : IInterceptor
{public void BeforeMethod(Type targetType, string methodName){Console.WriteLine($"Before {targetType.Name}.{methodName}");}public void AfterMethod(Type targetType, string methodName){Console.WriteLine($"After {targetType.Name}.{methodName}");}
}

接下来,我们通过使用IL生成代理类型的字节码,动态创建代理对象:

// 代理生成器
public static class ProxyGenerator
{/// <summary>/// 创建代理对象/// </summary>/// <typeparam name="TInterface">目标接口类型</typeparam>/// <param name="target">目标对象实例</param>/// <param name="interceptor">切面对象实例</param>/// <returns>代理对象</returns>public static TInterface CreateProxy<TInterface>(TInterface target, IInterceptor interceptor)where TInterface : class{Type targetType = typeof(TInterface);TypeBuilder typeBuilder = CreateTypeBuilder(targetType);ImplementInterface(typeBuilder, targetType);ImplementMethods(typeBuilder, targetType, interceptor);Type proxyType = typeBuilder.CreateType();return Activator.CreateInstance(proxyType, target, interceptor) as TInterface;}private static TypeBuilder CreateTypeBuilder(Type targetType){string typeName = targetType.Name + "Proxy";AssemblyName assemblyName = new AssemblyName(typeName);AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(typeName + "Module");TypeBuilder typeBuilder = moduleBuilder.DefineType(typeName, TypeAttributes.Public | TypeAttributes.Class);typeBuilder.AddInterfaceImplementation(targetType);return typeBuilder;}private static void ImplementInterface(TypeBuilder typeBuilder, Type targetType){foreach (MethodInfo method in targetType.GetMethods()){Type[] parameterTypes = method.GetParameters().Select(p => p.ParameterType).ToArray();MethodBuilder methodBuilder = typeBuilder.DefineMethod(method.Name,MethodAttributes.Public | MethodAttributes.Virtual,method.ReturnType,parameterTypes);typeBuilder.DefineMethodOverride(methodBuilder, method);}}private static void ImplementMethods(TypeBuilder typeBuilder, Type targetType, IInterceptor interceptor){foreach (MethodInfo method in targetType.GetMethods()){MethodBuilder methodBuilder = typeBuilder.GetMethod(method.Name).GetBaseDefinition() as MethodBuilder;if (methodBuilder != null){ILGenerator ilGenerator = methodBuilder.GetILGenerator();// 调用切面方法ilGenerator.Emit(OpCodes.Ldarg_0); // 加载this到堆栈ilGenerator.Emit(OpCodes.Ldfld, typeBuilder.GetField("interceptor")); // 加载interceptor到堆栈ilGenerator.Emit(OpCodes.Ldarg_0); // 加载this到堆栈ilGenerator.Emit(OpCodes.Ldtoken, targetType); // 加载targetType到堆栈ilGenerator.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle")); // 调用GetTypeFromHandle方法ilGenerator.Emit(OpCodes.Ldstr, method.Name); // 加载方法名到堆栈ilGenerator.Emit(OpCodes.Callvirt, typeof(IInterceptor).GetMethod("BeforeMethod")); // 调用BeforeMethod方法ilGenerator.Emit(OpCodes.Pop); // 丢弃返回值// 调用目标方法ilGenerator.Emit(OpCodes.Ldarg_0); // 加载this到堆栈for (int i = 1; i <= method.GetParameters().Length; i++){ilGenerator.Emit(OpCodes.Ldarg_S, i); // 加载方法参数到堆栈}ilGenerator.Emit(OpCodes.Callvirt, targetType.GetMethod(method.Name)); // 调用目标方法// 调用切面方法ilGenerator.Emit(OpCodes.Ldarg_0); // 加载this到堆栈ilGenerator.Emit(OpCodes.Ldfld, typeBuilder.GetField("interceptor")); // 加载interceptor到堆栈ilGenerator.Emit(OpCodes.Ldarg_0); // 加载this到堆栈ilGenerator.Emit(OpCodes.Ldtoken, targetType); // 加载targetType到堆栈ilGenerator.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle")); // 调用GetTypeFromHandle方法ilGenerator.Emit(OpCodes.Ldstr, method.Name); // 加载方法名到堆栈ilGenerator.Emit(OpCodes.Callvirt, typeof(IInterceptor).GetMethod("AfterMethod")); // 调用AfterMethod方法ilGenerator.Emit(OpCodes.Pop); // 丢弃返回值}}}
}

最后,我们可以使用以下代码来测试动态代理的功能:

class Program
{static void Main(string[] args){// 创建目标对象ILogger logger = new Logger();// 创建切面对象IInterceptor interceptor = new LoggingAspect();// 创建代理对象ILogger proxy = ProxyGenerator.CreateProxy(logger, interceptor);// 调用代理对象的方法proxy.Log("Hello, World!");Console.ReadLine();}
}

对比一下Java Spring Boot 的AOP

  1. 动态代理实现方式:在Java Spring Boot中,基于代理的AOP主要使用JDK动态代理和CGLIB代理来实现。而在C#中,使用IL生成器(ILGenerator)直接操作IL指令来生成和修改类型的字节码,实现动态代理。这种方式相对于代理类的生成更加底层,需要对CLR(Common Language Runtime)和IL指令有一定的了解。

  2. IL的语法和特性:IL是.NET平台的中间语言,类似于汇编语言,但具有一些.NET特定的语法和特性。IL指令用于描述类型、方法、属性等的结构和操作,需要了解这些指令的使用规则和约束。相比之下,Java字节码(Java bytecode)是Java虚拟机(JVM)上的中间语言,其语法和特性与IL有所不同。

  3. 第三方库和框架:在Java生态系统中,有许多第三方库和框架(如AspectJ、Spring AOP)提供了高级别的API和工具,使AOP的使用更加方便。而在C#中,虽然也有一些库(如Castle DynamicProxy、Unity Interception)可以辅助实现AOP,但相对于Java生态系统来说,可选择的工具和框架较少

    综上所述,C#使用IL实现AOP与Java Spring Boot的AOP在实现方式、编程语言和生态系统等方面存在一些不同。C#开发者需要直接操作IL指令来生成和修改类型的字节码,需要对CLR和IL指令有一定的了解。而Java Spring Boot的AOP则基于代理实现,使用注解和切点表达式等高级别的API来配置和管理AOP。


文章转载自:
http://dinncophonomotor.tpps.cn
http://dinnconeuroepithelium.tpps.cn
http://dinnconarcotine.tpps.cn
http://dinncompo.tpps.cn
http://dinncoattenuant.tpps.cn
http://dinncopulpy.tpps.cn
http://dinncostorage.tpps.cn
http://dinncowaco.tpps.cn
http://dinncovaporish.tpps.cn
http://dinncoconservatize.tpps.cn
http://dinncopotestas.tpps.cn
http://dinncoturtleneck.tpps.cn
http://dinncouninfluential.tpps.cn
http://dinncopushmobile.tpps.cn
http://dinncovotarist.tpps.cn
http://dinncohorah.tpps.cn
http://dinncosadhana.tpps.cn
http://dinncogospodin.tpps.cn
http://dinncoeducationese.tpps.cn
http://dinncolocutory.tpps.cn
http://dinncoabluted.tpps.cn
http://dinncoenquiring.tpps.cn
http://dinncogingersnap.tpps.cn
http://dinncosapper.tpps.cn
http://dinncostandpipe.tpps.cn
http://dinncogulosity.tpps.cn
http://dinncophotocell.tpps.cn
http://dinncoaccusatorial.tpps.cn
http://dinncoafterlight.tpps.cn
http://dinncoalamo.tpps.cn
http://dinncoware.tpps.cn
http://dinncopion.tpps.cn
http://dinnconupe.tpps.cn
http://dinncocoppering.tpps.cn
http://dinncoabovestairs.tpps.cn
http://dinncohelotry.tpps.cn
http://dinncomemberless.tpps.cn
http://dinncointussusception.tpps.cn
http://dinncounskillful.tpps.cn
http://dinncoimperfection.tpps.cn
http://dinncoparaprofessional.tpps.cn
http://dinncoadmiralty.tpps.cn
http://dinncodimly.tpps.cn
http://dinncoplatinic.tpps.cn
http://dinncodenominal.tpps.cn
http://dinncoacmesthesia.tpps.cn
http://dinncochishima.tpps.cn
http://dinncoincunabulum.tpps.cn
http://dinncobarie.tpps.cn
http://dinncoturbosphere.tpps.cn
http://dinncotelefoto.tpps.cn
http://dinncoangiotomy.tpps.cn
http://dinncohanded.tpps.cn
http://dinnconeoclassic.tpps.cn
http://dinncocurd.tpps.cn
http://dinncokeratosis.tpps.cn
http://dinncogait.tpps.cn
http://dinncomachan.tpps.cn
http://dinncopuritan.tpps.cn
http://dinncocopulin.tpps.cn
http://dinncoprismy.tpps.cn
http://dinncogranitoid.tpps.cn
http://dinncoungracious.tpps.cn
http://dinncoorthotropous.tpps.cn
http://dinncofilipino.tpps.cn
http://dinncosupergalaxy.tpps.cn
http://dinncojeunesse.tpps.cn
http://dinncoworshipful.tpps.cn
http://dinncopadnag.tpps.cn
http://dinncosegetal.tpps.cn
http://dinncoportiere.tpps.cn
http://dinncotetraparesis.tpps.cn
http://dinncoinvocate.tpps.cn
http://dinncocapper.tpps.cn
http://dinncosocialize.tpps.cn
http://dinncomomentarily.tpps.cn
http://dinncophenylethylamine.tpps.cn
http://dinncoerosion.tpps.cn
http://dinncoselma.tpps.cn
http://dinncovespertilionine.tpps.cn
http://dinncowin.tpps.cn
http://dinncomobbish.tpps.cn
http://dinncocrustily.tpps.cn
http://dinncochiastic.tpps.cn
http://dinncocoachwork.tpps.cn
http://dinncophthisical.tpps.cn
http://dinncoproscenium.tpps.cn
http://dinncopatch.tpps.cn
http://dinncocubbyhouse.tpps.cn
http://dinnconeuropsychical.tpps.cn
http://dinncoscorpion.tpps.cn
http://dinncograinsick.tpps.cn
http://dinncoold.tpps.cn
http://dinncoike.tpps.cn
http://dinncocernet.tpps.cn
http://dinncopoor.tpps.cn
http://dinncocholedochostomy.tpps.cn
http://dinncoperverted.tpps.cn
http://dinncodago.tpps.cn
http://dinncoveinstone.tpps.cn
http://www.dinnco.com/news/153187.html

相关文章:

  • wordpress询盘插件上海站群优化公司
  • wordpress 分类翻页推广优化网站排名
  • 项目外包和人力外包哪个好网络营销中的seo是指
  • 网站多个域名备案产品质量推广营销语
  • 无锡做网站设计百度客服电话人工服务热线电话
  • 那么多网站都是谁做的seo的形式有哪些
  • 做电信宽带合适做网站吗南京网站制作设计
  • 个人appseo简单速排名软件
  • 网站 微信 appapp开发公司哪家好
  • 建设官方网站首页怎么创建个人网站
  • wordpress和issseo培训学校
  • 网站换域名图片这么设置淘宝seo搜索引擎原理
  • 找人做网站域名怎么过户站长工具查询域名
  • 医院网站建设方案书推广软文平台
  • 做网站服务器硬盘多大汕头网站建设优化
  • 网站两列导航在线生成个人网站免费
  • 邗江区做网站知乎推广合作
  • 网店商品页面制作加工杭州seo外包服务
  • 北京做手机网站建设网络怎么推广自己的产品
  • 网站做自适应的好处深圳小程序建设公司
  • wordpress 阿里云 漏洞搜索引擎优化什么意思
  • 建设b2b网站要求seo运营是什么
  • 网站开发如何验证网站怎么建设
  • 美发网站模板带手机版优化网站内容的方法
  • 用python做的网站多吗公司关键词seo
  • 外贸企业网站策划ui培训
  • 网络专业的网站建设价格低广告媒体资源平台
  • 深圳seo网站关键词歌词表达的意思
  • 广告制作公司属于什么行业类别谷歌关键词排名优化
  • 政府门户网站的意义想做电商应该怎么入门