public static string CreateParameterChecks(Parameter[] parameters, int indent = 3) { StringBuilder result = new StringBuilder(); for (int i = 0; i < parameters.Length; i++) { if (!parameters[i].Required) continue; string type = GetType(parameters[i].DataType); result.Append(GetIndent(indent)); switch (type) { case "string": result.AppendFormat("Ensure.NotNullNorEmpty(\"{0}\",{0});\n", GetParameterName(parameters[i])); break; case "long": result.AppendFormat("Ensure.IdIsValid(\"{0}\",{0});\n", GetParameterName(parameters[i])); break; default: result.AppendFormat("Ensure.NotNull(\"{0}\",{0});\n", GetParameterName(parameters[i])); break; } } return result.ToString(); }
public static string CreateBodyRequest(Parameter[] parameters) { StringBuilder result = new StringBuilder(); foreach (var parameter in parameters) { if (parameter.ParamType == ParamType.Body) { if (String.IsNullOrEmpty(parameter.Name)) return String.Empty; // The parameter is the body if (result.Length == 0) { result.AppendLine("var requestBody = new Dictionary<string, object>();"); } result.AppendLine(String.Format("requestBody.Add(\"{0}\",{1});", parameter.Name, GetParameterName(parameter))); } } return result.ToString(); }
public static string CreateQueryString(Parameter[] parameters, int indent = 3) { //var queryString = new QueryString(); //queryString["fieldType"] = fieldType; //queryString["subDomain"] = subDomain; StringBuilder result = new StringBuilder(); foreach (var parameter in parameters) { if (parameter.ParamType == ParamType.Query) { if (result.Length == 0) { result.Append(GetIndent(indent)); result.AppendLine("var queryString = new QueryString();"); } result.Append(GetIndent(indent)); result.AppendLine(String.Format("queryString.Add(\"{0}\",{1});", parameter.Name, GetParameterName(parameter))); } } return result.ToString(); }
public static bool IsNullableType(Parameter prop) { string type = GetType(prop.DataType); return !prop.Required && !prop.DataType.EndsWith("[]") && type != "string" && (!type.Contains(".") || (type.EndsWith("Enum"))); }
public static string GetParameterName(Parameter parameter) { if (String.IsNullOrEmpty(parameter.Name)) return "requestBody"; if (parameter.Name == "class") return "class_"; return parameter.Name.Replace('.', '_'); }