コード例 #1
0
    static string GetCSharpString(ExcelData excelData)
    {
        StringBuilder sb = StringBuilderPool.Alloc();

        for (int i = 0; i < excelData._fieldNameList.Count; i++)
        {
            sb.AppendLine("\t/// <summary>");
            sb.Append("\t/// " + excelData._fieldNameList[i]);
            if (!string.IsNullOrEmpty(excelData._commentList[i]))
            {
                sb.AppendFormat("({0})", excelData._commentList[i]);
            }
            sb.AppendLine();
            sb.AppendLine("\t/// <summary>");
            sb.Append("\tpublic ");
            switch (excelData._typeNameList[i].ToLower())
            {
            case "byte": sb.Append("short: ");  break;

            case "string": sb.Append("string "); break;

            case "bool": sb.Append("bool ");   break;

            case "int":
            case "int32": sb.Append("int ");    break;

            case "uint32": sb.Append("uint ");   break;

            case "int64":
            case "long": sb.Append("long ");   break;

            case "datetime": sb.Append("DateTime "); break;
            }
            sb.Append(excelData._fieldNameList[i]);
            sb.AppendLine(";");
        }

        var builder = StringBuilderPool.Alloc();

        builder.Append(TemplateString.String_Config_Template);
        builder.Replace("{FILE_NAME}", excelData.tableName);
        builder.Replace("{ITEM_CLASS_VARIABLE}", sb.ToString());
        string result = builder.ToString();

        StringBuilderPool.Recycle(sb);
        StringBuilderPool.Recycle(builder);

        return(result);
    }