예제 #1
0
        private Func <object[], object> FindMethod(string name, int argCount)
        {
            for (int i = ExecutionState.SubmissionStateCount - 1; i >= 0; i--)
            {
                var sub = ExecutionState.GetSubmissionState(i);
                if (sub != null)
                {
                    var type   = sub.GetType();
                    var method = FindMethod(type, name, argCount);
                    if (method != null)
                    {
                        return((args) => method.Invoke(sub, args));
                    }
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Create a delegate to a method declared by the script.
        /// </summary>
        public TDelegate CreateDelegate <TDelegate>(string name)
        {
            var delegateInvokeMethod = typeof(TDelegate).GetTypeInfo().GetDeclaredMethod("Invoke");

            for (int i = ExecutionState.SubmissionStateCount - 1; i >= 0; i--)
            {
                var sub = ExecutionState.GetSubmissionState(i);
                if (sub != null)
                {
                    var type   = sub.GetType();
                    var method = FindMatchingMethod(type, name, delegateInvokeMethod);
                    if (method != null)
                    {
                        return((TDelegate)(object)method.CreateDelegate(typeof(TDelegate), sub));
                    }
                }
            }

            return(default(TDelegate));
        }