示例#1
0
        /// <summary>
        ///     Invokes this instance.
        /// </summary>
        public void Invoke()
        {
            object source = this.Context.Value;

            if (source != null)
            {
                object[] paras = this.Parameters != null?this.Parameters.Select(item => item.Value).ToArray() : null;

                var methodInfo = DynamicEngine.GetMethodInfo(source.GetType(), this.Method, paras, false);
                if (methodInfo != null)
                {
                    DynamicEngine.InvokeMethod(source, methodInfo, paras);
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Handles the <see cref="E:AttachEventOccurred" /> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
        internal void OnAttachEventOccurred(object sender, EventArgs args)
        {
            if (!this.IsAlive || !this.eventTarget.IsNotNullAndAlive())
            {
                this.DetachEvent();
                return;
            }

            if (this.eventFilter != null && !this.eventFilter(sender, args))
            {
                return;
            }

            DynamicEngine.InvokeMethod(this.Target, this.HandlerName, new[] { sender, args });
        }
示例#3
0
        /// <summary>
        ///     Determines whether this instance can invoke.
        /// </summary>
        /// <returns><c>true</c> if this instance can invoke; otherwise, <c>false</c>.</returns>
        /// <exception cref="MissingMemberException">The attach method does not return boolean value.</exception>
        public bool CanInvoke()
        {
            object source = this.Context.Value;

            if (source != null)
            {
                object[] paras = this.Parameters != null?this.Parameters.Select(item => item.Value).ToArray() : null;

                var methodInfo = DynamicEngine.GetMethodInfo(source.GetType(), this.Method, paras, false);
                if (methodInfo != null)
                {
                    object value = DynamicEngine.InvokeMethod(source, methodInfo, paras);
                    if (!(value is bool))
                    {
                        throw new MissingMemberException(
                                  string.Format("The attach method {0} does not return Boolean value", this.Method));
                    }

                    return((bool)value);
                }
            }

            return(false);
        }