예제 #1
0
        public object CallMethod(object target, string method, object[] args)
        {
            Type t = target as Type;

            if (t == null)
            {
                t = target.GetType();
            }
            Delegate del = GetMethod(target, method, args);

            if (del == null)
            {
                //del = DelegateUtility.MethodToInstanceDelegate(target, t.GetMethod(method));
                MethodInfo info = ReflectionUtility.FindMethod(t, method, args);
                if (info.IsStatic)
                {
                    TypeDef typeDef = _assembly.GetTypeDef(t);
                    if (typeDef == null || !typeDef.allowStaticMembers)
                    {
                        throw new Exception("Static member access is not allowed on type " + t.Name);
                    }
                }
                del = DelegateUtility.MethodToInstanceDelegate(target, ReflectionUtility.FindMethod(t, method, args));
                Cache(target, method, del, args);
            }

            return(SmartCall(del, args));
        }
예제 #2
0
        public object CallMethod(object target, MethodInfo method, object[] args)
        {
            Delegate del = GetMethod(target, method.Name, args);

            if (del == null)
            {
                del = DelegateUtility.MethodToInstanceDelegate(target, method);
                Cache(target, method.Name, del, args);
            }

            return(SmartCall(del, args));
        }