コード例 #1
0
ファイル: ResponseManagerBase.cs プロジェクト: m9ra/ServeRick
        private ActionInfo resolveAction(MethodInfo action)
        {
            //TODO add support for attributes
            var responseParam   = Expression.Parameter(typeof(Response));
            var managerConstant = Expression.Constant(this);
            var actionConstant  = Expression.Constant(this);

            var controller             = Expression.New(action.DeclaringType);
            var controllerVar          = Expression.Variable(controller.Type);
            var responseControllerType = typeof(ResponseController);
            var methodFlags            = BindingFlags.NonPublic | BindingFlags.Instance;

            var actionMethod = Expression.Block(new[] { controllerVar },
                                                Expression.Assign(controllerVar, controller),
                                                Expression.Call(controllerVar, responseControllerType.GetMethod("SetResponse", methodFlags), managerConstant, responseParam),
                                                Expression.Call(controllerVar, action)
                                                );

            var handler = Expression.Lambda <ResponseHandler>(actionMethod, responseParam).Compile();

            var item = WebItem.Runtime(handler);
            var name = action.Name.Replace("__", ".");

            return(new ActionInfo("/" + name, item));
        }
コード例 #2
0
ファイル: ResponseManagerBase.cs プロジェクト: m9ra/ServeRick
        public ResponseManagerBase(WebApplication application, string rootPath, params Type[] controllers)
        {
            RootPath    = rootPath + Path.DirectorySeparatorChar;
            Application = application;
            foreach (var controller in controllers)
            {
                foreach (var action in controller.GetMethods())
                {
                    if (action.DeclaringType.IsSubclassOf(typeof(ResponseController)))
                    {
                        registerAction(action);
                    }
                }
            }

            _304 = WebItem.Runtime(_handler_304);
        }