CodeGenUtil.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. namespace Admin.NET.Core.Util;
  2. /// <summary>
  3. /// 代码生成帮助类
  4. /// </summary>
  5. public static class CodeGenUtil
  6. {
  7. public static string ConvertDataType(string dataType)
  8. {
  9. switch (dataType)
  10. {
  11. case "text":
  12. case "varchar":
  13. case "char":
  14. case "nvarchar":
  15. case "nchar":
  16. case "timestamp":
  17. return "string";
  18. case "int":
  19. return "int";
  20. case "smallint":
  21. return "Int16";
  22. case "tinyint":
  23. return "byte";
  24. case "bigint":
  25. case "integer": // sqlite数据库
  26. return "long";
  27. case "bit":
  28. return "bool";
  29. case "money":
  30. case "smallmoney":
  31. case "numeric":
  32. case "decimal":
  33. return "decimal";
  34. case "real":
  35. return "Single";
  36. case "datetime":
  37. case "smalldatetime":
  38. return "DateTime";
  39. case "float":
  40. return "double";
  41. case "image":
  42. case "binary":
  43. case "varbinary":
  44. return "byte[]";
  45. case "uniqueidentifier":
  46. return "Guid";
  47. default:
  48. return "object";
  49. }
  50. }
  51. /// <summary>
  52. /// 数据类型转显示类型
  53. /// </summary>
  54. /// <param name="dataType"></param>
  55. /// <returns></returns>
  56. public static string DataTypeToEff(string dataType)
  57. {
  58. if (string.IsNullOrEmpty(dataType)) return "";
  59. return dataType switch
  60. {
  61. "string" => "Input",
  62. "int" => "InputNumber",
  63. "long" => "Input",
  64. "float" => "Input",
  65. "double" => "Input",
  66. "decimal" => "Input",
  67. "bool" => "Switch",
  68. "Guid" => "Input",
  69. "DateTime" => "DatePicker",
  70. _ => "Input",
  71. };
  72. }
  73. // 是否通用字段
  74. public static bool IsCommonColumn(string columnName)
  75. {
  76. var columnList = new List<string>()
  77. {
  78. "CreateTime", "UpdateTime", "CreateUserId", "UpdateUserId", "IsDelete"
  79. };
  80. return columnList.Contains(columnName);
  81. }
  82. }