public AjaxMethod(MethodInfo methodInfo, Type targetType, AjaxAttribute ajaxAttribute) : this(ajaxAttribute)
        {
            _methodInfo = methodInfo;
            _targetType = targetType;

            _url = "~/_$ajax$_.axd/" + UrlHelper.EncodeToUrl(targetType.Assembly.GetName().Name) + '/' + UrlHelper.EncodeToUrl(targetType.FullName) + '/' + UrlHelper.EncodeToUrl(methodInfo.Name);
        }
Exemple #2
0
        public AjaxMethod(MethodInfo methodInfo, Type targetType, AjaxAttribute ajaxAttribute) : this(ajaxAttribute)
        {
            _methodInfo = methodInfo;
            _targetType = targetType;

            _url = "~/_$ajax$_.axd/" + UrlHelper.EncodeToUrl(targetType.Assembly.GetName().Name) + '/' + UrlHelper.EncodeToUrl(targetType.FullName) + '/' + UrlHelper.EncodeToUrl(methodInfo.Name);
        }
 private AjaxMethod(AjaxAttribute ajaxAttribute)
 {
     _useFormData = ajaxAttribute.UseFormData;
     _javaScriptAlias = ajaxAttribute.JavaScriptAlias;
     _returnXml = ajaxAttribute.ReturnXml;
 }
Exemple #4
0
        internal ControllerClass(Type classType)
        {
            List <Route> routes = new List <Route>();

            _classType = classType;
            _name      = classType.Name;

            _defaultViewName = _name;

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

            if (_classType.IsDefined(typeof(AllowCachingAttribute), true))
            {
                _allowCaching = true;
            }

            if (IsViewComponent)
            {
                ComponentNameAttribute[] nameAttributes = (ComponentNameAttribute[])classType.GetCustomAttributes(typeof(ComponentNameAttribute), false);

                if (nameAttributes.Length > 0)
                {
                    _name = nameAttributes[0].Name;
                }
            }

            UrlAttribute[] urlAttributes = (UrlAttribute[])classType.GetCustomAttributes(typeof(UrlAttribute), false);

            foreach (UrlAttribute urlAttribute in urlAttributes)
            {
                routes.Add(new Route(urlAttribute.Path, _name, urlAttribute.Action));
            }

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

                currentClassType = currentClassType.BaseType;
            }

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

                if (currentClassType.IsDefined(typeof(LayoutAttribute), false))
                {
                    _defaultLayoutName = ((LayoutAttribute)currentClassType.GetCustomAttributes(typeof(LayoutAttribute), false)[0]).LayoutName ?? "";
                }

                if (currentClassType.IsDefined(typeof(ViewAttribute), false))
                {
                    _defaultViewName = ((ViewAttribute)currentClassType.GetCustomAttributes(typeof(ViewAttribute), false)[0]).ViewName ?? "";
                }

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

                foreach (MethodInfo methodInfo in methods)
                {
                    if (methodInfo.IsSpecialName)
                    {
                        continue;
                    }

                    if (methodInfo.IsDefined(typeof(BeforeActionAttribute), true))
                    {
                        _setupMethods.Add(methodInfo);
                    }
                    else if (methodInfo.IsDefined(typeof(AfterActionAttribute), true))
                    {
                        _teardownMethods.Add(methodInfo);
                    }
                    else if (methodInfo.IsDefined(typeof(AjaxAttribute), true))
                    {
                        AjaxAttribute ajaxAttribute = (AjaxAttribute)methodInfo.GetCustomAttributes(typeof(AjaxAttribute), true)[0];

                        _ajaxMethods[methodInfo.Name] = new AjaxMethod(methodInfo, _classType, ajaxAttribute);
                    }
                    else if (methodInfo.IsPublic)
                    {
                        _actionMethods[methodInfo.Name] = new ActionMethod(methodInfo);

                        urlAttributes = (UrlAttribute[])methodInfo.GetCustomAttributes(typeof(UrlAttribute), false);

                        foreach (UrlAttribute urlAttr in urlAttributes)
                        {
                            routes.Add(new Route(urlAttr.Path, _name, methodInfo.Name));
                        }
                    }
                }
            }

            _routes = routes.ToArray();
        }
Exemple #5
0
 private AjaxMethod(AjaxAttribute ajaxAttribute)
 {
     _useFormData     = ajaxAttribute.UseFormData;
     _javaScriptAlias = ajaxAttribute.JavaScriptAlias;
     _returnXml       = ajaxAttribute.ReturnXml;
 }