public void Fire(LNBCBase instance) { if (instance.Disposed) { return; } Method.Invoke(instance, null); }
public void Fire <T>(T data, LNBCBase instance) where T : class { if (instance.Disposed) { return; } if (_parameters.Length == 1 && _parameters[0].ParameterType == typeof(T)) { _data[0] = data; Method.Invoke(instance, _data); } else { Method.Invoke(instance, null); } }
public LNElementInstance Bind(LNBCBase instance, params string[] methodNames) { if (!_instancePool.ContainsKey(instance.CreateSequence)) { lock (_instancePool) { if (!_instancePool.ContainsKey(instance.CreateSequence)) { _instancePool.Add(instance.CreateSequence, instance); instance.Disposing += () => { Remove(instance.CreateSequence); }; } } } foreach (var methodName in methodNames) { var typeInfo = instance.GetType(); var method = typeInfo.GetMethod(methodName); var attr = method.GetCustomAttribute <LNElementEventAttribute>(); var attrType = attr.GetType(); if (!_eventPool.ContainsKey(attrType)) { lock (_eventPool) { if (!_eventPool.ContainsKey(attrType)) { _eventPool.Add(attrType, new Dictionary <int, LNElementEvent>()); } switch (attr) { case OnClickEventAttribute _: this.BindElementMouseEvent("click", nameof(OnClick)); break; case OnMouseOverEventAttribute _: this.BindElementMouseEvent("mouseover", nameof(OnMouseOver)); break; case OnMouseEnterEventAttribute _: this.BindElementMouseEvent("mouseenter", nameof(OnMouseEnter)); break; case OnMouseDownEventAttribute _: this.BindElementMouseEvent("mousedown", nameof(OnMouseDown)); break; case OnMouseUpEventAttribute _: this.BindElementMouseEvent("mouseup", nameof(OnMouseUp)); break; case OnMouseMoveEventAttribute _: this.BindElementMouseEvent("mousemove", nameof(OnMouseMove)); break; case OnMouseOutEventAttribute _: this.BindElementMouseEvent("mouseout", nameof(OnMouseOut)); break; case OnContextMenuEventAttribute _: this.BindElementMouseEvent("contextmenu", nameof(OnContextMenu)); break; case OnBlurEventAttribute _: this.BindElementNotificationEvent("blur", nameof(OnBlur)); break; case OnChangeEventAttribute _: this.BindElementNotificationEvent("change", nameof(OnChange)); break; case OnFocusEventAttribute _: this.BindElementNotificationEvent("focus", nameof(OnFocus)); break; case OnFocusInEventAttribute _: this.BindElementNotificationEvent("focusin", nameof(OnFocusIn)); break; case OnFocusOutEventAttribute _: this.BindElementNotificationEvent("focusout", nameof(OnFocusOut)); break; case OnInputEventAttribute _: this.BindElementNotificationEvent("input", nameof(OnInput)); break; case OnKeyDownEventAttribute _: this.BindElementKeyboardEvent("keydown", nameof(OnKeyDown)); break; case OnKeypressEventAttribute _: this.BindElementKeyboardEvent("keypress", nameof(OnKeypress)); break; case OnKeyupEventAttribute _: this.BindElementKeyboardEvent("keyup", nameof(OnKeyup)); break; case OnScrollEventAttribute _: this.BindElementScroll(nameof(OnScroll)); break; default: break; } } } lock (_eventPool) { if (!_eventPool[attrType].ContainsKey(instance.CreateSequence)) { _eventPool[attrType].Add(instance.CreateSequence, new LNElementEvent(method, attr)); } } } return(this); }