CodeGenUtil.cs
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using NCC.Dependency;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace NCC.Common.Util
{
/// <summary>
/// 代码生成帮助类
/// </summary>
[SuppressSniffer]
/// <summary>
/// 代码生成帮助类
/// </summary>
public static class CodeGenUtil
{
public static string ConvertDataType(string dataType)
{
switch (dataType.ToLower())
{
case "text":
case "varchar":
case "char":
case "nvarchar":
case "nchar":
case "timestamp":
case "string":
return "string";
case "int":
return "int?";
case "smallint":
return "int?";
case "tinyint":
return "byte";
case "bigint":
case "integer"://sqlite数据库
return "long";
case "bit":
return "bool";
case "money":
case "smallmoney":
case "numeric":
case "decimal":
return "decimal";
case "real":
return "Single";
case "datetime":
case "datetime2":
case "smalldatetime":
return "DateTime?";
case "float":
return "double";
case "image":
case "binary":
case "varbinary":
return "byte[]";
case "uniqueidentifier":
return "Guid";
default:
return "object";
}
}
/// <summary>
/// 数据类型转显示类型
/// </summary>
/// <param name="dataType"></param>
/// <returns></returns>
public static string DataTypeToEff(string dataType)
{
if (string.IsNullOrEmpty(dataType)) return "";
return dataType switch
{
"string" => "input",
"int" => "inputnumber",
"long" => "input",
"float" => "input",
"double" => "input",
"decimal" => "input",
"bool" => "switch",
"Guid" => "input",
"DateTime" => "datepicker",
_ => "input",
};
}
// 是否通用字段
public static bool IsCommonColumn(string columnName)
{
var columnList = new List<string>()
{
"CreatedTime", "UpdatedTime", "CreatedUserId", "CreatedUserName", "UpdatedUserId", "UpdatedUserName", "IsDeleted"
};
return columnList.Contains(columnName);
}
}
}