1 回答
TA贡献2021条经验 获得超8个赞
我最终编写了一个方法来检查已注册处理程序的类型的每个接口:
private IEventHandler<TEvent> GetHandler<TEvent>(Type type = null) where TEvent : IEvent
{
object handler;
type = type ?? typeof(TEvent);
if (_container.TryResolve(typeof(IEventHandler<>).MakeGenericType(type), out handler))
{
return (IEventHandler<TEvent>)handler;
}
else
{
foreach (var t in type.GetInterfaces())
{
var h = GetHandler<TEvent>(t);
if (h != null)
return h;
}
}
return null;
}
- 1 回答
- 0 关注
- 77 浏览
添加回答
举报