/// <summary> /// 该方法返回一个SourcableEvent对象,当用户扩展了SourcableEvent类时,可以重载此方法返回一个自己的SourcableEvent对象。 /// 或者更加对推荐的方式是,用户可以设计一个实现了ISourcableEvent的泛型接口SourcableEvent类来实现对SourcableEvent的扩展。 /// </summary> /// <param name="evnt">用户创建的事件对象</param> /// <returns>返回一个SourcableEvent对象</returns> protected virtual SourcableEvent CreateSourcableEvent(object evnt, long version) { var sourcableEventInterfaceType = typeof(ISourcableEvent <>).MakeGenericType(GetType()); if (ObjectContainer.IsRegistered(sourcableEventInterfaceType)) { return(MethodInvoker.InvokeMethod(sourcableEventInterfaceType, "Initialize", new object[] { this, evnt, version }) as SourcableEvent); } else { var sourcableEventType = typeof(SourcableEvent <>).MakeGenericType(GetType()); return(MethodInvoker.InvokeMethod(sourcableEventType, "Initialize", new object[] { this, evnt, version }) as SourcableEvent); } }
public static object InvokeMethod(Type objType, string methodName, params object[] parameters) { object obj = null; if (ObjectContainer.IsRegistered(objType)) { obj = ObjectContainer.Resolve(objType); } else { obj = Activator.CreateInstance(objType); } return(InvokeMethod(obj, methodName, parameters)); }