Commits

Edison Chuang  committed 4670e52

Code refactoring

* Changed some method name to meet naming convention.

  • Participants
  • Parent commits 8680d2f
  • Branches develop

Comments (0)

Files changed (1)

File source/MVC.ApiExplorer/ApiExploreView.cs

 			foreach (MethodInfo m in (model))
 			{
 				var actionName = getActionName(m);
-				var actionUrl = GetActionUrl(routeName, viewContext, controllerName, actionName);
+				var actionUrl = getActionUrl(routeName, viewContext, controllerName, actionName);
 
 				html.AppendFormat(@"<li class=""api"">({1}) <strong class=""api-name"">{0}</strong><br />", actionName, m.ReturnType.Name);
-				html.AppendFormat("<p>{0}</p>", GetDescription(m));
-				RenderHttpMethod(html, controllerName, actionName);
+				html.AppendFormat("<p>{0}</p>", getDescription(m));
+				renderHttpMethod(html, controllerName, actionName);
 				html.AppendFormat(@"<form id=""{0}_{1}_form"" action=""{2}"" method=""get"" target=""output""  enctype=""multipart/form-data"">", controllerName, actionName, actionUrl);
-				RenderAntiForgeryToken(viewContext, html, m);
+				renderAntiForgeryToken(viewContext, html, m);
 				html.Append("<table cellspacing=\"0\">");
 				var parameters = m.GetParameters();
 				foreach (var parameter in parameters)
 				{
 					Type fieldType = parameter.ParameterType;
 					string fieldName = parameter.Name;
-					string fieldDescription = GetDescription(parameter);
+					string fieldDescription = getDescription(parameter);
 
-					RenderField(htmlHelper, html, 0, fieldType, "", fieldName, fieldDescription);
+					renderField(htmlHelper, html, 0, fieldType, "", fieldName, fieldDescription);
 				}
 
 				html.Append("</table>");
 
 			writer.Write(html.ToString());
 		}
-		private static void RenderComplexField(HtmlHelper htmlHelper, StringBuilder html, string FieldNamespace, PropertyInfo[] properties, int deep)
+		private static void renderComplexField(HtmlHelper htmlHelper, StringBuilder html, string FieldNamespace, PropertyInfo[] properties, int deep)
 		{
 			html.AppendFormat(@"<fieldset class=""api-subfields""><legend>{0}:</legend>", FieldNamespace);
 			html.Append("<table cellspacing=\"0\">");
 			{
 				Type fieldType = property.PropertyType;
 				string fieldName = property.Name;
-				string fieldDescription = GetDescription(property);
+				string fieldDescription = getDescription(property);
 
-				RenderField(htmlHelper, html, deep, fieldType, FieldNamespace, fieldName, fieldDescription);
+				renderField(htmlHelper, html, deep, fieldType, FieldNamespace, fieldName, fieldDescription);
 			}
 			html.Append("</table>");
 			html.Append(@"</fieldset>");
 		}
-		private static void RenderField(HtmlHelper htmlHelper, StringBuilder html, int deep, Type fieldType, string fieldNamespace, string fieldName, string fieldDescription)
+		private static void renderField(HtmlHelper htmlHelper, StringBuilder html, int deep, Type fieldType, string fieldNamespace, string fieldName, string fieldDescription)
 		{
 			html.Append("<tr>");
-			if (IsGeneralField(fieldType))
+			if (isGeneralField(fieldType))
 			{
-				RenderInput(htmlHelper, html, fieldType, fieldNamespace, fieldName, fieldDescription, false);
+				renderInput(htmlHelper, html, fieldType, fieldNamespace, fieldName, fieldDescription, false);
 			}
-			else if (IsFileUploadField(fieldType))
+			else if (isFileUploadField(fieldType))
 			{
-				RenderInput(htmlHelper, html, fieldType, fieldNamespace, fieldName, fieldDescription, true);
+				renderInput(htmlHelper, html, fieldType, fieldNamespace, fieldName, fieldDescription, true);
 			}
 			else
 			{
 				//Complex model binding
-				if (IsDerivedFromGenericType(fieldType, typeof(IEnumerable<>)))
+				if (isDerivedFromGenericType(fieldType, typeof(IEnumerable<>)))
 				{
 					//Enumerable type
 					var innerFieldType = fieldType.GetGenericArguments()[0];
-					bool isComplexType = !IsGeneralField(innerFieldType) && !IsFileUploadField(innerFieldType);
+					bool isComplexType = !isGeneralField(innerFieldType) && !isFileUploadField(innerFieldType);
 					
 					for (int i = 0; i < 3; i++)
 					{
 						html.Append(htmlHelper.Hidden(fieldName + ".Index", i).ToHtmlString());
 						string enumerablefieldName = string.Format("{0}[{1}]", fieldName, i);
-						RenderField(htmlHelper, html, deep, innerFieldType, fieldNamespace, enumerablefieldName, fieldDescription);
+						renderField(htmlHelper, html, deep, innerFieldType, fieldNamespace, enumerablefieldName, fieldDescription);
 					}
 				}
 				else
 						deep++;
 						var subProperties = fieldType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
 						fieldNamespace = string.IsNullOrEmpty(fieldNamespace) ? fieldName : string.Format("{0}.{1}", fieldNamespace, fieldName);
-						RenderComplexField(htmlHelper, html, fieldNamespace, subProperties, deep);
+						renderComplexField(htmlHelper, html, fieldNamespace, subProperties, deep);
 					}
 					html.Append("</td>");
 				}
 			html.Append("</tr>");
 		}
 
-		private static void RenderInput(HtmlHelper htmlHelper, StringBuilder html, Type fieldType, string fieldNamespace, string fieldName, string fieldDescription, bool isFileUpload)
+		private static void renderInput(HtmlHelper htmlHelper, StringBuilder html, Type fieldType, string fieldNamespace, string fieldName, string fieldDescription, bool isFileUpload)
 		{
 			var name = string.IsNullOrEmpty(fieldNamespace) ? fieldName : string.Format("{0}.{1}", fieldNamespace, fieldName);
 			html.AppendFormat(@"<td>({1}) <span>{0}:</span></td><td>{3}</td><td>{2}</td>",
 				name,
-				SimplifyTypeName(fieldType),
+				simplifyTypeName(fieldType),
 				fieldDescription,
 				isFileUpload ? htmlHelper.TextBox(name, "", new { type="file"}) : htmlHelper.TextBox(name)
 				);
 		}
-		private static void RenderHttpMethod(StringBuilder html, string controllerName, string methodName)
+		private static void renderHttpMethod(StringBuilder html, string controllerName, string methodName)
 		{
 			html.AppendFormat(
 @"<fieldset class=""api-fields"">
 <input type=""radio"" id=""{0}_{1}_delete"" name=""{0}_{1}"" onchange=""var form = document.getElementById('{0}_{1}_form'); form.setAttribute('method','post'); var inputTag = document.getElementById('{0}_{1}_put_http_method_override'); if(inputTag){{form.removeChild(inputTag);}} inputTag = document.createElement('input'); inputTag.id='{0}_{1}_delete_http_method_override'; inputTag.type='hidden'; inputTag.name='X-HTTP-Method-Override'; inputTag.value='DELETE'; form.appendChild( inputTag );"" ><label for=""{0}_{1}_delete"">DELETE</label><br />",
 controllerName, methodName);
 		}
-		private static void RenderAntiForgeryToken(ViewContext viewContext, StringBuilder html, MethodInfo m)
+		private static void renderAntiForgeryToken(ViewContext viewContext, StringBuilder html, MethodInfo m)
 		{
 			if (m.GetCustomAttributes(typeof(ValidateAntiForgeryTokenAttribute), true).Length > 0)
 			{
 			}
 		}
 
-		private static string GetDescription(ParameterInfo parameter)
+		private static string getDescription(ParameterInfo parameter)
 		{
 			var attributes = parameter.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
 			return attributes.Length > 0 ? ((DescriptionAttribute)attributes[0]).Description : string.Empty;
 		}
-		private static string GetDescription(PropertyInfo property)
+		private static string getDescription(PropertyInfo property)
 		{
 			var attributes = property.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
 			return attributes.Length > 0 ? ((DescriptionAttribute)attributes[0]).Description : string.Empty;
 		}
-		private static string GetDescription(MethodInfo method)
+		private static string getDescription(MethodInfo method)
 		{
 			var attributes = method.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
 			return attributes.Length > 0 ? ((DescriptionAttribute)attributes[0]).Description : string.Empty;
 		}
 
-		private static bool IsGeneralField(Type fieldType)
+		private static bool isGeneralField(Type fieldType)
 		{
 			return fieldType.IsPrimitive
 						|| fieldType.Equals(typeof(string))
 						|| fieldType.Equals(typeof(decimal))
 						|| (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable<>));//Determine whether a field type object represents a Nullable type
 		}
-		private static bool IsFileUploadField(Type fieldType)
+		private static bool isFileUploadField(Type fieldType)
 		{
 			return fieldType.Equals(typeof(HttpPostedFileBase));
 		}
-		private static bool IsDerivedFromGenericType(Type type, Type genericType)
+		private static bool isDerivedFromGenericType(Type type, Type genericType)
 		{
 			if (!type.IsGenericType)
 			{
 				return false;
 			}
 			
-			return IsDerivedFromGenericType(type.BaseType, genericType);
+			return isDerivedFromGenericType(type.BaseType, genericType);
 		}
 
 		/// <summary>
 		/// Try to get the action url with specific route name.
 		/// </summary>
-		private string GetActionUrl(string routeName, ViewContext viewContext, string controllerName, string actionName)
+		private string getActionUrl(string routeName, ViewContext viewContext, string controllerName, string actionName)
 		{
 			var url = UrlHelper.GenerateUrl(routeName, actionName, controllerName, null, RouteTable.Routes, viewContext.RequestContext, true);
 			if (url == null)
 			{
-				url = GetActionUrl(viewContext, controllerName, actionName);
+				url = getActionUrl(viewContext, controllerName, actionName);
 			}
 
 			return url;
 		/// <summary>
 		/// Try to get the first matched action url.
 		/// </summary>
-		private string GetActionUrl(ViewContext viewContext, string controllerName, string actionName)
+		private string getActionUrl(ViewContext viewContext, string controllerName, string actionName)
 		{
 			var url = "";
 			FieldInfo field = typeof(RouteCollection).GetField("_namedMap", BindingFlags.Instance | BindingFlags.NonPublic);
 			return url;
 		}
 
-		private static string SimplifyTypeName(Type type)
+		private static string simplifyTypeName(Type type)
 		{
 			var result = "";
 			if (type.Equals(typeof(Byte)))
 			else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
 			{
 				var arg = type.GetGenericArguments()[0];
-				result = SimplifyTypeName(arg) + "?";
+				result = simplifyTypeName(arg) + "?";
 			}
 			else if (type.Equals(typeof(HttpPostedFileBase)))
 			{