Пример #1
0
        /// <summary>
        /// Calls the method pointed with the provided parameter.
        /// </summary>
        /// <param name="param">Parameter to pass to method.</param>
        /// <returns>True if the method was called, false if the target has been garbage collected.</returns>
        public bool Invoke(T param)
        {
            object target = Target;

            if (target == null || !IsAlive)
            {
                return(false);
            }

            if (_openAction == null)
            {
                _openAction = OpenAction.CreateOpenAction <T>(Method);
            }

            _openAction(target, param);
            return(true);
        }
Пример #2
0
        private void DispatchEvent(object sender, TEventArgs e)
        {
            // if the target is still alive, call the event handler, otherwise detach from the event
            var target = _target.Target;

            if (target != null && _target.IsAlive)
            {
                if (_delegate == null)
                {
                    _delegate = OpenAction.CreateOpenAction <object, TEventArgs>(_methodInfo);
                }

                _delegate(target, sender, e);
            }
            else if (_unregisterMethod != null)
            {
                _unregisterMethod(Handler);
            }
        }