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; }
internal ControllerClass(Type classType) { _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); List <Route> routes = urlAttributes.Select(attribute => new Route(attribute.Path, _name, attribute.Action)).ToList(); 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); routes.AddRange(from urlAttr in urlAttributes select new Route(urlAttr.Path, _classType, methodInfo.Name)); } } } _routes = routes.ToArray(); }