CodeGenUtil.cs 2.6 KB

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