예제 #1
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            // Get type args of the call
            Type[] typeArgs = ExposedObjectHelper.GetTypeArgs(binder);
            if (typeArgs != null && typeArgs.Length == 0)
            {
                typeArgs = null;
            }

            var key = _is_ignore_case ? binder.Name.ToLower() : binder.Name;

            //
            // Try to call a non-generic instance method
            //
            if (typeArgs == null &&
                m_staticMethods.ContainsKey(key) &&
                m_staticMethods[key].ContainsKey(args.Length) &&
                ExposedObjectHelper.InvokeBestMethod(args, null, m_staticMethods[key][args.Length], out result))
            {
                return(true);
            }

            //
            // Try to call a generic instance method
            //
            if (m_staticMethods.ContainsKey(key) &&
                m_staticMethods[key].ContainsKey(args.Length))
            {
                List <MethodInfo> methods = new List <MethodInfo>();

                foreach (var method in m_genStaticMethods[key][args.Length])
                {
                    if (method.GetGenericArguments().Length == typeArgs.Length)
                    {
                        methods.Add(method.MakeGenericMethod(typeArgs));
                    }
                }

                if (ExposedObjectHelper.InvokeBestMethod(args, null, methods, out result))
                {
                    return(true);
                }
            }

            result = null;
            if (_is_throw_exception_when_method_not_exits)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
 /// <summary>
 /// 尝试执行非泛型方法
 /// </summary>
 /// <param name="methodname"></param>
 /// <param name="result"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public bool InvokeMethod(string methodname, out object result, params object[] args)
 {
     if (m_instanceMethods.ContainsKey(methodname) &&
         m_instanceMethods[methodname].ContainsKey(args.Length) &&
         ExposedObjectHelper.InvokeBestMethod(args, m_object, m_instanceMethods[methodname][args.Length], out result))
     {
         return(true);
     }
     else
     {
         result = null;
         return(false);
     }
 }
예제 #3
0
        /// <summary>
        /// 尝试执行非泛型方法
        /// </summary>
        /// <param name="methodname"></param>
        /// <param name="target"></param>
        /// <param name="result"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool InvokeMethod(string methodname, object target, out object result, params object[] args)
        {
            var key = _is_ignore_case ? methodname.ToLower() : methodname;

            if (m_instanceMethods.ContainsKey(key) &&
                m_instanceMethods[key].ContainsKey(args.Length) &&
                ExposedObjectHelper.InvokeBestMethod(args, target, m_instanceMethods[key][args.Length], out result))
            {
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }