Exemplo n.º 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));
        }
Exemplo n.º 2
0
        private MethodInfo FindMethod(Type targetType, string identifier, object[] argumentNodes)
        {
            List <Type> typeList = new List <Type>();

            for (int i = 0; i < argumentNodes.Length; i += 1)
            {
                typeList.Add(CompilerUtility.GetReturnType(argumentNodes[i]));
            }
            return(ReflectionUtility.FindMethod(targetType, identifier, typeList.ToArray()));
        }