/// <summary> /// 注册一个事件监听器 /// </summary> /// <param name="dispatcher">事件调度器</param> /// <param name="eventName">事件名称</param> /// <param name="target">事件调用目标</param> /// <param name="method">事件处理方法</param> /// <returns>事件对象</returns> public static IEvent On(this IDispatcher dispatcher, string eventName, object target, string method = null) { Guard.NotEmptyOrNull(eventName, nameof(eventName)); Guard.Requires <ArgumentException>(method != string.Empty); Guard.Requires <ArgumentNullException>(target != null); var methodInfo = target.GetType().GetMethod(method ?? Str.Method(eventName), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); Guard.Requires <ArgumentNullException>(methodInfo != null); return(dispatcher.On(eventName, target, methodInfo, target)); }
/// <summary> /// 绑定一个方法到容器 /// </summary> /// <param name="container">服务容器</param> /// <param name="method">方法名</param> /// <param name="target">调用目标</param> /// <param name="call">调用方法</param> public static IMethodBind BindMethod(this IContainer container, string method, object target, string call = null) { Guard.NotEmptyOrNull(method, "method"); Guard.Requires <ArgumentNullException>(target != null); return(container.BindMethod(method, target, target.GetType().GetMethod(call ?? Str.Method(method)))); }
/// <summary> /// 注册一个事件监听器 /// </summary> /// <param name="dispatcher">事件调度器</param> /// <param name="eventName">事件名称</param> /// <param name="target">事件调用目标</param> /// <param name="method">事件处理方法</param> /// <returns>事件对象</returns> public static IEvent On(this IDispatcher dispatcher, string eventName, object target, string method = null) { Guard.NotEmptyOrNull(eventName, "eventName"); Guard.Requires <ArgumentException>(method != string.Empty); Guard.Requires <ArgumentNullException>(target != null); return(dispatcher.On(eventName, target, target.GetType().GetMethod(method ?? Str.Method(eventName)))); }