当前位置:
首页 > Python基础教程 >
-
python的日期处理
说明:这里只是VirtualMethodInterceptor拦截器的处理,下面代码中用到的ViewModelCommandBehavior是对IInterceptionBehavior接口的实现
主要就是用反射获取到相应的方法来执行指定的操作
问题:通常是用下面注释掉的 interception.RegisterSingleton 来注册,但是当需要注册的类很多或者不确定时会很不方便,所以改用下面的方法来自动完成相关类的注册
void SetInterceptor()
{
IUnityContainer unityContainer = new UnityContainer();
IUnityContainer interception = unityContainer.AddNewExtension<Interception>();
//interception.RegisterSingleton<CustomViewModel>(new Interceptor<VirtualMethodInterceptor>(), new InterceptionBehavior<ViewModelCommandBehavior>());
//return;
Assembly assem = Assembly.GetExecutingAssembly();
var types = assem.ExportedTypes;
foreach (Type item in types)
{
//具体做哪些限制根据实际情况来
if (item.IsClass && typeof(ViewModelBase).IsAssignableFrom(item))
{
//这里可以加一些其它的限制,目前值用于CustomViewModel
if (item.FullName == typeof(CustomViewModel).FullName)
{
//可以参考上面的RegisterSingleton方法调用,这里的RegisterSingleton是用的扩展类中的扩展方法
//所以在查找方法时是直接在扩展类中找的,而且因为扩展方法是静态方法所以Invoke执行时对象可以设置为null
var method = typeof(UnityContainerExtensions).GetMethods(BindingFlags.Static | BindingFlags.Public)
.Where(x => x.Name == "RegisterSingleton" && x.IsGenericMethod == true && x.GetGenericArguments().Length == 1
&& x.GetParameters().Length == 2 && x.GetParameters()[1].ParameterType.FullName == typeof(InjectionMember[]).FullName).FirstOrDefault();
if (method != null)
{
method = method.MakeGenericMethod(new Type[] { item });
InjectionMember[] injectionMembers = new InjectionMember[2];
injectionMembers[0] = new Interceptor<VirtualMethodInterceptor>();
injectionMembers[1] = new InterceptionBehavior<ViewModelCommandBehavior>();
object[] pars = new object[2];
pars[0] = interception;
pars[1] = injectionMembers;
method.Invoke(null, pars);
}
}
}
}
}
出处:https://www.cnblogs.com/myxxzly/p/16617196.html
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式











