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 關注
- 133 瀏覽
添加回答
舉報