public virtual void Register(IAggregate aggregate) { if (aggregate == null) { throw new ArgumentNullException("aggregate"); } this.registered = aggregate; var state = aggregate.GetSnapshot(); // Get instance methods named Apply with one parameter returning void var applyMethods = state.GetType() .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(m => m.Name == "Apply" && m.GetParameters().Length == 1 && m.ReturnParameter.ParameterType == typeof(void)) .Select(m => new { Method = m, MessageType = m.GetParameters().Single().ParameterType }); foreach (var apply in applyMethods) { var applyMethod = apply.Method; this.handlers.Add(apply.MessageType, m => applyMethod.Invoke(state, new[] { m as object })); } }