コード例 #1
0
ファイル: DynamicEventListener.cs プロジェクト: wqhenry/Catel
        /// <summary>
        /// Called when the event occurs.
        /// </summary>
// ReSharper disable UnusedMember.Global
        public void OnEvent()
// ReSharper restore UnusedMember.Global
        {
            EventOccurred.SafeInvoke(this);

            if (_handlerInstance != null)
            {
                var handlerMethodInfo = _handlerInstance.GetType().GetMethodEx(HandlerName, BindingFlagsHelper.GetFinalBindingFlags(true, false));
                if (handlerMethodInfo == null)
                {
                    throw Log.ErrorAndCreateException <NotSupportedException>("Cannot find the '{0}' method, implement the '{0}' method on '{1}'", EventName, _handlerInstance.GetType().Name);
                }

                handlerMethodInfo.Invoke(_handlerInstance, null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Called when the event occurs.
        /// </summary>
// ReSharper disable UnusedMember.Global
        public void OnEvent()
// ReSharper restore UnusedMember.Global
        {
            EventOccurred.SafeInvoke(this, EventArgs.Empty);

            if (_handlerInstance != null)
            {
                var handlerMethodInfo = _handlerInstance.GetType().GetMethodEx(HandlerName, BindingFlagsHelper.GetFinalBindingFlags(true, false));
                if (handlerMethodInfo == null)
                {
                    string error = string.Format("Cannot find the '{0}' method, implement the '{0}' method on '{1}'", EventName, _handlerInstance.GetType().Name);
                    Log.Error(error);

                    throw new NotSupportedException(error);
                }

                handlerMethodInfo.Invoke(_handlerInstance, null);
            }
        }