104 lines
3.0 KiB
C#
104 lines
3.0 KiB
C#
using AutoBet.ApiGenerator.Extensions;
|
|||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Text;
|
||
|
|
|
||
|
|
namespace AutoBet.ApiGenerator
|
||
|
|
{
|
||
|
|
public static class CSharpClassBuilder
|
||
|
|
{
|
||
|
|
public static void Summary(StringBuilder sb, string summary, bool isClassSummary = false)
|
||
|
|
{
|
||
|
|
var indentSpaces = isClassSummary ? 4 : 8;
|
||
|
|
if (!String.IsNullOrWhiteSpace(summary))
|
||
|
|
{
|
||
|
|
sb.AppendWithIndent(indentSpaces, "/// <summary>\r\n");
|
||
|
|
|
||
|
|
var descriptionLines = summary.Trim().TrimEnd('\n').Replace("\r", "").Split('\n');
|
||
|
|
foreach (var line in descriptionLines)
|
||
|
|
{
|
||
|
|
sb.AppendWithIndent(indentSpaces, "/// ");
|
||
|
|
sb.Append(line.Trim());
|
||
|
|
sb.AppendLine();
|
||
|
|
}
|
||
|
|
sb.AppendWithIndent(indentSpaces, "/// </summary>\r\n");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void ClassFooter(StringBuilder sb)
|
||
|
|
{
|
||
|
|
sb.AppendWithIndent(4, "}");
|
||
|
|
sb.AppendLine();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void ClassHeader(StringBuilder sb, string name)
|
||
|
|
{
|
||
|
|
sb.AppendWithIndent(4, "public class ");
|
||
|
|
sb.Append(name);
|
||
|
|
sb.AppendLine();
|
||
|
|
sb.AppendWithIndent(4, "{");
|
||
|
|
sb.AppendLine();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void EnumHeader(StringBuilder sb, string name)
|
||
|
|
{
|
||
|
|
sb.AppendWithIndent(4, "public enum ");
|
||
|
|
sb.Append(name);
|
||
|
|
sb.AppendLine();
|
||
|
|
sb.AppendWithIndent(4, "{");
|
||
|
|
sb.AppendLine();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void UsingHeader(StringBuilder sb, string namespaceValue, params string[] usings)
|
||
|
|
{
|
||
|
|
sb.AppendLine("using System;");
|
||
|
|
foreach (var value in usings)
|
||
|
|
{
|
||
|
|
sb.AppendFormat("using {0};", value);
|
||
|
|
sb.AppendLine();
|
||
|
|
}
|
||
|
|
|
||
|
|
sb.AppendLine();
|
||
|
|
sb.Append("namespace ");
|
||
|
|
sb.Append(namespaceValue);
|
||
|
|
sb.AppendLine();
|
||
|
|
sb.AppendLine("{");
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void UsingFooter(StringBuilder sb)
|
||
|
|
{
|
||
|
|
sb.Append("}");
|
||
|
|
}
|
||
|
|
|
||
|
|
public static string GetDataType(string responseType)
|
||
|
|
{
|
||
|
|
if (responseType.StartsWith("list("))
|
||
|
|
{
|
||
|
|
return GetCSharpType(responseType.Substring(5, responseType.Length - 6)) + "[]";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (responseType.StartsWith("set("))
|
||
|
|
{
|
||
|
|
return GetCSharpType(responseType.Substring(4, responseType.Length - 5)) + "[]";
|
||
|
|
}
|
||
|
|
|
||
|
|
return GetCSharpType(responseType);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static string GetCSharpType(string responseType)
|
||
|
|
{
|
||
|
|
switch (responseType)
|
||
|
|
{
|
||
|
|
case "i64":
|
||
|
|
return "long";
|
||
|
|
case "i32":
|
||
|
|
return "int";
|
||
|
|
case "dateTime":
|
||
|
|
return "DateTime";
|
||
|
|
default:
|
||
|
|
return responseType;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|