标签:vat imp make pre ted invoke 泛型 assembly uil
注册泛型接口的类:
builder.RegisterAssemblyTypes(typeof(IEventHandler<>).Assembly) .Where(t => t.IsClass && t.GetInterfaces().Any(i=>i.IsGenericType && i.GetGenericTypeDefinition()==typeof(IEventHandler<>))) .AsSelf() .AsImplementedInterfaces();
解析泛型接口:
var handlerType = typeof(IEventHandler<>).MakeGenericType(typeof(TEvent)); //TEvent是泛型 var handlerInstances = Activator.Invoke(typeof(IEnumerable<>).MakeGenericType(handlerType)) as IEnumerable;
标签:vat imp make pre ted invoke 泛型 assembly uil
原文地址:https://www.cnblogs.com/fanfan-90/p/12100239.html