Exemplo n.º 1
0
        public ControllerClass(Type classType, string name)
        {
            _classType = classType;

            _name = name;

            Type         currentClassType = _classType;
            Stack <Type> pageTypeStack    = new Stack <Type>();

            while (currentClassType != typeof(Controller) && currentClassType != null)
            {
                pageTypeStack.Push(currentClassType);

                currentClassType = currentClassType.BaseType;
            }

            while (pageTypeStack.Count > 0)
            {
                currentClassType = pageTypeStack.Pop();

                MethodInfo[] methods = currentClassType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                foreach (MethodInfo methodInfo in methods)
                {
                    if (methodInfo.IsSpecialName)
                    {
                        continue;
                    }
#if MEDIUMLEVEL
                    MethodSchema data = new MethodSchema(methodInfo.Name, methodInfo, methodInfo.GetParameters(), methodInfo.IsStatic);
#else
                    MethodSchema data = new MethodSchema(methodInfo.Name, BaseMethodInvoker.GetMethodInvoker(methodInfo), methodInfo.GetParameters(), methodInfo.IsStatic);
#endif
                    if (methodInfo.Name.StartsWith("Before"))
                    {
                        _beforeMethods.Add(data);
                    }
                    else if (methodInfo.Name.StartsWith("After"))
                    {
                        _afterMethods.Add(data);
                    }
                    else
                    {
                        if (_publicMethods.ContainsKey(methodInfo.Name))
                        {
                            _publicMethods[methodInfo.Name] = data;
                        }
                        else
                        {
                            _publicMethods.Add(methodInfo.Name, data);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static object Invoke(Controller controller, IList <MethodSchema> methods, object[] args)
        {
            Type[] argsType = new Type[args.Length];

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == null)
                {
                    throw new MissingMethodException();
                }

                argsType[i] = args[i].GetType();
            }

            MethodSchema currentMethod = null;

            foreach (MethodSchema m in methods)
            {
                if (m.Parameters.Length != args.Length)
                {
                    continue;
                }

                bool found = true;

                for (int i = 0; i < argsType.Length; i++)
                {
                    if (m.Parameters[i].ParameterType != argsType[i])
                    {
                        found = false;
                        break;
                    }
                }

                if (found)
                {
                    currentMethod = m;
                    break;
                }
            }

            if (currentMethod != null)
            {
                return(currentMethod.InvokeHandler.Invoke(controller, args));
            }
            else
            {
                throw new MissingMethodException();
            }
        }