Beispiel #1
0
        public static void RegisterHandlers(FakeBus bus, object obj)
        {
            var interfaces = obj.GetType().GetInterfaces().SelectMany(i => i.GetGenericArguments());

            foreach (var i in interfaces)
            {
                var handleMethod = obj.GetType().GetMethod("Handle", new Type[] { i });
                var del = Delegate.CreateDelegate(Expression.GetActionType(i), obj, handleMethod);

                MethodInfo register = bus.GetType().GetMethod("RegisterHandler").MakeGenericMethod(i);
                register.Invoke(bus, new object[] { del });
            }
        }