private string GetActionUrls(IEnumerable <MethodInfo> actions, ScriptUrlsInfo urlsInfo, Func <string, string, Type, string> getUrlFunc, string controllerName) { var sb = new StringBuilder(); foreach (MethodInfo action in actions) { sb.AppendLine(string.Format(" {0}: {{", action.Name.FirstCharacterToLower())); string method = null; if (action.GetCustomAttributes(urlsInfo.GetAttributeType).Any()) { method = "get"; } else if (action.GetCustomAttributes(urlsInfo.PostAttributeType).Any()) { method = "post"; } else if (action.GetCustomAttributes(urlsInfo.PutAttributeType).Any()) { method = "put"; } else if (action.GetCustomAttributes(urlsInfo.DeleteAttributeType).Any()) { method = "delete"; } sb.AppendLine(string.Format(" method: '{0}',", method)); sb.AppendLine(string.Format(" url: '{0}',", getUrlFunc(controllerName, action.Name, action.DeclaringType))); sb.AppendLine(" },"); } return(sb.ToString().TrimEnd().TrimEnd(',')); }
private string GetUrlsScriptObject(ScriptUrlsInfo urlsInfo, IEnumerable <Type> assemblyTypes, Func <string, string, Type, string> getUrlFunc) { var sb = new StringBuilder(); sb.AppendLine(string.Format(" module.{0} = {{", urlsInfo.JsObjectName)); sb.AppendLine(string.Format(" $type: '{0}',", urlsInfo.UrlType.ToString().FirstCharacterToLower())); sb.AppendLine(this.GetControllerUrls(assemblyTypes, urlsInfo, getUrlFunc)); sb.AppendLine(" };"); return(sb.ToString()); }
private string GetControllerUrls(IEnumerable <Type> assemblyTypes, ScriptUrlsInfo urlsInfo, Func <string, string, Type, string> getUrlFunc) { var sb = new StringBuilder(); foreach (Type type in assemblyTypes) { if (urlsInfo.ControllerType.IsAssignableFrom(type)) { string controllerName = type.Name.Substring(0, type.Name.Length - 10); sb.AppendLine(string.Format(" {0}: {{", controllerName.FirstCharacterToLower())); sb.AppendLine(string.Format(" $area: '{0}',", this.GetControllerArea(type).FirstCharacterToLower())); IEnumerable <MethodInfo> actions = type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public) .Where(method => !method.IsDefined(urlsInfo.NonActionAttributeType)); sb.AppendLine(this.GetActionUrls(actions, urlsInfo, getUrlFunc, controllerName)); sb.AppendLine(" },"); } } return(sb.ToString().TrimEnd().TrimEnd(',')); }