export-table-pulgin-csharp 1.1.96 → 1.1.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CSParseTool.d.ts +16 -0
- package/dist/CSParseTool.d.ts.map +1 -0
- package/dist/CSParseTool.js +267 -0
- package/dist/ExportCSPlugin.d.ts +1 -4
- package/dist/ExportCSPlugin.d.ts.map +1 -1
- package/dist/ExportCSPlugin.js +48 -300
- package/dist/ExportLiteDBCSPlugin.d.ts +8 -0
- package/dist/ExportLiteDBCSPlugin.d.ts.map +1 -0
- package/dist/ExportLiteDBCSPlugin.js +242 -0
- package/dist/ExportLiteDBUnityCSJsonPlugin.d.ts +10 -0
- package/dist/ExportLiteDBUnityCSJsonPlugin.d.ts.map +1 -0
- package/dist/ExportLiteDBUnityCSJsonPlugin.js +208 -0
- package/dist/ExportUnityCSJsonPlugin.d.ts.map +1 -1
- package/dist/ExportUnityCSJsonPlugin.js +5 -10
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/package.json +1 -1
- package/src/CSParseTool.ts +212 -0
- package/src/ExportCSPlugin.ts +14 -221
- package/src/ExportLiteDBCSPlugin.ts +242 -0
- package/src/ExportLiteDBUnityCSJsonPlugin.ts +212 -0
- package/src/ExportUnityCSJsonPlugin.ts +2 -8
- package/src/index.ts +4 -0
- package/test/testLiteDB.bat +2 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, iff, FieldType, makeFirstLetterLower, DataTable } from "export-table-lib"
|
|
3
|
+
|
|
4
|
+
export function TryConvValue(value: any, t: FieldType, f: Field): any {
|
|
5
|
+
try {
|
|
6
|
+
return ConvValue(value, t, f)
|
|
7
|
+
} catch (ex) {
|
|
8
|
+
if (ex instanceof TypeError) {
|
|
9
|
+
console.error(ex)
|
|
10
|
+
return null
|
|
11
|
+
} else {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function ConvValue(value: any, t: FieldType, f: Field): any {
|
|
18
|
+
if (t == "object") {
|
|
19
|
+
return JSON.parse(value)
|
|
20
|
+
} else if (t == "object[]") {
|
|
21
|
+
return JSON.parse(value)
|
|
22
|
+
} else if (t == "number" || t == "float") {
|
|
23
|
+
return JSON.parse(value)
|
|
24
|
+
} else if (t == "int" || t == "long") {
|
|
25
|
+
return parseInt(value)
|
|
26
|
+
} else if (t == "number[]" || t == "float[]") {
|
|
27
|
+
return JSON.parse(value)
|
|
28
|
+
} else if (t == "int[]") {
|
|
29
|
+
return JSON.parse(value)
|
|
30
|
+
} else if (t == "long[]") {
|
|
31
|
+
return JSON.parse(value)
|
|
32
|
+
} else if (t == "uid") {
|
|
33
|
+
return JSON.parse(value)
|
|
34
|
+
} else if (t == "bool") {
|
|
35
|
+
try {
|
|
36
|
+
return !!JSON.parse(value)
|
|
37
|
+
} catch (ex) {
|
|
38
|
+
console.log(ex)
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
} else if (t == "bool[]") {
|
|
42
|
+
return JSON.parse(value)
|
|
43
|
+
} else if (t == "string") {
|
|
44
|
+
return value
|
|
45
|
+
} else if (t == "string[]") {
|
|
46
|
+
return JSON.parse(value)
|
|
47
|
+
} else if (t == "fk") {
|
|
48
|
+
return value
|
|
49
|
+
} else if (t == "fk[]") {
|
|
50
|
+
return value
|
|
51
|
+
} else if (t == "any") {
|
|
52
|
+
console.log(f)
|
|
53
|
+
throw new TypeError(`invalid type ${f.name}:<${f.rawType} => any>`)
|
|
54
|
+
} else if (t == "key") {
|
|
55
|
+
return JSON.parse(t)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw new TypeError(`invalid unkown type ${f.name}:<${f.rawType} => ${f.type} << ${t}>`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function ConvValue2Literal(value: any, t: FieldType, f: Field): string {
|
|
62
|
+
if (t == "object") {
|
|
63
|
+
//throw new Error("invalid type <object>")
|
|
64
|
+
let convert: string[] = [];
|
|
65
|
+
for (let k in value) {
|
|
66
|
+
convert.push(`{"${k}","${(value as any)[k].toString()}"}`);
|
|
67
|
+
};
|
|
68
|
+
return `new Dictionary<string,string>(${convert.length}){${convert}}`;
|
|
69
|
+
} else if (t == "object[]") {
|
|
70
|
+
let values = value as object[];
|
|
71
|
+
//throw new Error("invalid type <object[]>")
|
|
72
|
+
return `new List<Dictionary<string,string>>(){${values.map((val) => {
|
|
73
|
+
let convert: string[] = [];
|
|
74
|
+
for (let k in val) {
|
|
75
|
+
convert.push(`{"${k}","${(val as any)[k].toString()}"}`);
|
|
76
|
+
};
|
|
77
|
+
return `new Dictionary<string,string>(${convert.length}){${convert}}`;
|
|
78
|
+
})}}`
|
|
79
|
+
} else if (t == "number" || t == "int" || t == "long") {
|
|
80
|
+
return `${value}`
|
|
81
|
+
} else if (t == "number[]") {
|
|
82
|
+
let values = value as number[]
|
|
83
|
+
return `new double[]{${values.join(", ")}}`
|
|
84
|
+
} else if (t == "float[]") {
|
|
85
|
+
let values = value as number[]
|
|
86
|
+
return `new float[]{${values.join(", ")}}`
|
|
87
|
+
} else if (t == "int[]") {
|
|
88
|
+
let values = value as number[]
|
|
89
|
+
return `new int[]{${values.join(", ")}}`
|
|
90
|
+
} else if (t == "long[]") {
|
|
91
|
+
let values = value as number[]
|
|
92
|
+
return `new long[]{${values.join(", ")}}`
|
|
93
|
+
} else if (t == "uid") {
|
|
94
|
+
return `${value}`
|
|
95
|
+
} else if (t == "bool") {
|
|
96
|
+
return `${value}`
|
|
97
|
+
} else if (t == "bool[]") {
|
|
98
|
+
let values = value as boolean[]
|
|
99
|
+
return `new bool[]{${values.join(", ")}}`
|
|
100
|
+
} else if (t == "string") {
|
|
101
|
+
// return `"${value}"`
|
|
102
|
+
return JSON.stringify(value)
|
|
103
|
+
} else if (t == "string[]") {
|
|
104
|
+
let values = value as string[]
|
|
105
|
+
return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`
|
|
106
|
+
} else if (t == "fk") {
|
|
107
|
+
return `${value}`
|
|
108
|
+
} else if (t == "fk[]") {
|
|
109
|
+
let values = value as number[]
|
|
110
|
+
return `new int[]{${values.join(", ")}}`
|
|
111
|
+
} else if (t == "any") {
|
|
112
|
+
console.log(f)
|
|
113
|
+
throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
|
|
114
|
+
} else if (t == "key") {
|
|
115
|
+
return `${value}`
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export let isSkipExportDefaults0 = process.argv.findIndex(v => v == "--SkipDefaults") >= 0
|
|
122
|
+
|
|
123
|
+
export let firstLetterUpper = function (str: string) {
|
|
124
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
125
|
+
};
|
|
126
|
+
export let firstLetterLower = function (str: string) {
|
|
127
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
128
|
+
};
|
|
129
|
+
export let convMemberName = function (str: string) {
|
|
130
|
+
return str.split("_").map(s => firstLetterUpper(s)).join("")
|
|
131
|
+
}
|
|
132
|
+
export let convVarName = firstLetterLower
|
|
133
|
+
|
|
134
|
+
export let getFieldType = function (f: Field) {
|
|
135
|
+
let t = f.type
|
|
136
|
+
if (t == "object") {
|
|
137
|
+
//throw new Error("invalid type <Dictionary<string,string>>")
|
|
138
|
+
return "Dictionary<string,string>"
|
|
139
|
+
} else if (t == "object[]") {
|
|
140
|
+
//throw new Error("invalid type <Dictionary<string,string>[]>")
|
|
141
|
+
return "List<Dictionary<string,string>>"
|
|
142
|
+
} else if (t == "number") {
|
|
143
|
+
return "double";
|
|
144
|
+
} else if (t == "number[]") {
|
|
145
|
+
return "double[]";
|
|
146
|
+
} else if (t == "float") {
|
|
147
|
+
return "float";
|
|
148
|
+
} else if (t == "float[]") {
|
|
149
|
+
return "float[]";
|
|
150
|
+
} else if (t == "int") {
|
|
151
|
+
return "int";
|
|
152
|
+
} else if (t == "int[]") {
|
|
153
|
+
return "int[]";
|
|
154
|
+
} else if (t == "long") {
|
|
155
|
+
return "long";
|
|
156
|
+
} else if (t == "long[]") {
|
|
157
|
+
return "long[]";
|
|
158
|
+
} else if (t == "uid") {
|
|
159
|
+
return "int";
|
|
160
|
+
} else if (t == "bool") {
|
|
161
|
+
return "bool";
|
|
162
|
+
} else if (t == "bool[]") {
|
|
163
|
+
return "bool[]";
|
|
164
|
+
} else if (t == "string") {
|
|
165
|
+
return "string";
|
|
166
|
+
} else if (t == "string[]") {
|
|
167
|
+
return "string[]";
|
|
168
|
+
} else if (t == "fk") {
|
|
169
|
+
return "int";
|
|
170
|
+
} else if (t == "fk[]") {
|
|
171
|
+
return "int[]";
|
|
172
|
+
} else if (t == "any") {
|
|
173
|
+
console.log(f)
|
|
174
|
+
throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
|
|
175
|
+
} else if (t == "key") {
|
|
176
|
+
return "string";
|
|
177
|
+
} else {
|
|
178
|
+
throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
|
|
179
|
+
}
|
|
180
|
+
return t;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export let getFkFieldType = function (tables: DataTable[], field: Field) {
|
|
184
|
+
return tables.find(a => a.name == field.fkTableName)!.fields!.find(a => a.name == field.fkFieldName)!.type
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export const genValue = (value: any, f: Field): string => {
|
|
188
|
+
return ConvValue2Literal(value, f.type, f)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const getTitle = (v: Field) => {
|
|
192
|
+
return v.describe.split("\n")[0]
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export const getDescripts = (v: Field) => {
|
|
196
|
+
return v.describe.split("\n")
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export const convTupleArrayType = (f: Field) => {
|
|
200
|
+
let line0 = f.rawType.replaceAll(/(?<=[^\w])(number)(?=[^\w]|$)/g, "double").replaceAll(/(?<=[^\w])(boolean)(?=[^\w]|$)/g, "bool");
|
|
201
|
+
console.log(line0)
|
|
202
|
+
let m = line0.match(/\@\((\w+),(\w+)\)(\[\])?/)
|
|
203
|
+
if (m != null) {
|
|
204
|
+
let type1 = m[1]
|
|
205
|
+
let type2 = m[2]
|
|
206
|
+
let isArray = m[3] != null
|
|
207
|
+
let line = `public System.Tuple<${type1}, ${type2}>${isArray ? "[]" : ""} ${convMemberName(f.name)}Obj;`
|
|
208
|
+
return line;
|
|
209
|
+
} else {
|
|
210
|
+
return `public ${line0} ${convMemberName(f.name)}Obj;`
|
|
211
|
+
}
|
|
212
|
+
}
|
package/src/ExportCSPlugin.ts
CHANGED
|
@@ -1,126 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, iff, FieldType } from "export-table-lib"
|
|
2
|
+
import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, iff, FieldType, makeFirstLetterLower, DataTable } from "export-table-lib"
|
|
3
|
+
import { convMemberName, convTupleArrayType, convVarName, firstLetterUpper, genValue, getDescripts, getFieldType, getFkFieldType, getTitle, isSkipExportDefaults0 } from "./CSParseTool"
|
|
3
4
|
import * as fs from "fs-extra"
|
|
4
5
|
|
|
5
|
-
export function TryConvValue(value: any, t: FieldType, f: Field): any {
|
|
6
|
-
try {
|
|
7
|
-
return ConvValue(value, t, f)
|
|
8
|
-
} catch (ex) {
|
|
9
|
-
if (ex instanceof TypeError) {
|
|
10
|
-
console.error(ex)
|
|
11
|
-
return null
|
|
12
|
-
} else {
|
|
13
|
-
return null
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function ConvValue(value: any, t: FieldType, f: Field): any {
|
|
19
|
-
if (t == "object") {
|
|
20
|
-
return JSON.parse(value)
|
|
21
|
-
} else if (t == "object[]") {
|
|
22
|
-
return JSON.parse(value)
|
|
23
|
-
} else if (t == "number" || t == "float") {
|
|
24
|
-
return JSON.parse(value)
|
|
25
|
-
} else if (t == "int" || t == "long") {
|
|
26
|
-
return parseInt(value)
|
|
27
|
-
} else if (t == "number[]" || t == "float[]") {
|
|
28
|
-
return JSON.parse(value)
|
|
29
|
-
} else if (t == "int[]") {
|
|
30
|
-
return JSON.parse(value)
|
|
31
|
-
} else if (t == "long[]") {
|
|
32
|
-
return JSON.parse(value)
|
|
33
|
-
} else if (t == "uid") {
|
|
34
|
-
return JSON.parse(value)
|
|
35
|
-
} else if (t == "bool") {
|
|
36
|
-
try {
|
|
37
|
-
return !!JSON.parse(value)
|
|
38
|
-
} catch (ex) {
|
|
39
|
-
console.log(ex)
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
} else if (t == "bool[]") {
|
|
43
|
-
return JSON.parse(value)
|
|
44
|
-
} else if (t == "string") {
|
|
45
|
-
return value
|
|
46
|
-
} else if (t == "string[]") {
|
|
47
|
-
return JSON.parse(value)
|
|
48
|
-
} else if (t == "fk") {
|
|
49
|
-
return value
|
|
50
|
-
} else if (t == "fk[]") {
|
|
51
|
-
return value
|
|
52
|
-
} else if (t == "any") {
|
|
53
|
-
console.log(f)
|
|
54
|
-
throw new TypeError(`invalid type ${f.name}:<${f.rawType} => any>`)
|
|
55
|
-
} else if (t == "key") {
|
|
56
|
-
return JSON.parse(t)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
throw new TypeError(`invalid unkown type ${f.name}:<${f.rawType} => ${t}>`)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function ConvValue2Literal(value: any, t: FieldType, f: Field): string {
|
|
63
|
-
if (t == "object") {
|
|
64
|
-
//throw new Error("invalid type <object>")
|
|
65
|
-
let convert: string[] = [];
|
|
66
|
-
for (let k in value) {
|
|
67
|
-
convert.push(`{"${k}","${(value as any)[k].toString()}"}`);
|
|
68
|
-
};
|
|
69
|
-
return `new Dictionary<string,string>(${convert.length}){${convert}}`;
|
|
70
|
-
} else if (t == "object[]") {
|
|
71
|
-
let values = value as object[];
|
|
72
|
-
//throw new Error("invalid type <object[]>")
|
|
73
|
-
return `new List<Dictionary<string,string>>(){${values.map((val) => {
|
|
74
|
-
let convert: string[] = [];
|
|
75
|
-
for (let k in val) {
|
|
76
|
-
convert.push(`{"${k}","${(val as any)[k].toString()}"}`);
|
|
77
|
-
};
|
|
78
|
-
return `new Dictionary<string,string>(${convert.length}){${convert}}`;
|
|
79
|
-
})}}`
|
|
80
|
-
} else if (t == "number" || t == "int" || t == "long") {
|
|
81
|
-
return `${value}`
|
|
82
|
-
} else if (t == "number[]") {
|
|
83
|
-
let values = value as number[]
|
|
84
|
-
return `new double[]{${values.join(", ")}}`
|
|
85
|
-
} else if (t == "float[]") {
|
|
86
|
-
let values = value as number[]
|
|
87
|
-
return `new float[]{${values.join(", ")}}`
|
|
88
|
-
} else if (t == "int[]") {
|
|
89
|
-
let values = value as number[]
|
|
90
|
-
return `new int[]{${values.join(", ")}}`
|
|
91
|
-
} else if (t == "long[]") {
|
|
92
|
-
let values = value as number[]
|
|
93
|
-
return `new long[]{${values.join(", ")}}`
|
|
94
|
-
} else if (t == "uid") {
|
|
95
|
-
return `${value}`
|
|
96
|
-
} else if (t == "bool") {
|
|
97
|
-
return `${value}`
|
|
98
|
-
} else if (t == "bool[]") {
|
|
99
|
-
let values = value as boolean[]
|
|
100
|
-
return `new bool[]{${values.join(", ")}}`
|
|
101
|
-
} else if (t == "string") {
|
|
102
|
-
// return `"${value}"`
|
|
103
|
-
return JSON.stringify(value)
|
|
104
|
-
} else if (t == "string[]") {
|
|
105
|
-
let values = value as string[]
|
|
106
|
-
return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`
|
|
107
|
-
} else if (t == "fk") {
|
|
108
|
-
return `${value}`
|
|
109
|
-
} else if (t == "fk[]") {
|
|
110
|
-
let values = value as number[]
|
|
111
|
-
return `new int[]{${values.join(", ")}}`
|
|
112
|
-
} else if (t == "any") {
|
|
113
|
-
console.log(f)
|
|
114
|
-
throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
|
|
115
|
-
} else if (t == "key") {
|
|
116
|
-
return `${value}`
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
var isSkipExportDefaults0 = process.argv.findIndex(v => v == "--SkipDefaults") >= 0
|
|
123
|
-
|
|
124
6
|
export function export_stuff(paras: HandleSheetParams): string | null {
|
|
125
7
|
let {
|
|
126
8
|
datas,
|
|
@@ -140,102 +22,11 @@ export function export_stuff(paras: HandleSheetParams): string | null {
|
|
|
140
22
|
isSkipExportDefaults = true
|
|
141
23
|
}
|
|
142
24
|
|
|
143
|
-
let firstLetterUpper = function (str: string) {
|
|
144
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
145
|
-
};
|
|
146
|
-
let firstLetterLower = function (str: string) {
|
|
147
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
148
|
-
};
|
|
149
|
-
let convMemberName = function (str: string) {
|
|
150
|
-
return str.split("_").map(s => firstLetterUpper(s)).join("")
|
|
151
|
-
}
|
|
152
|
-
let convVarName = firstLetterLower
|
|
153
|
-
|
|
154
25
|
let RowClass = firstLetterUpper(name)
|
|
155
26
|
let initFunc = name + "Init"
|
|
156
27
|
let mapfield = fields.find(a => a.type == "key")//如果是map,则生成对应的map
|
|
157
28
|
let mapName = name + "Map"
|
|
158
29
|
|
|
159
|
-
let getFieldType = function (f: Field) {
|
|
160
|
-
let t = f.type
|
|
161
|
-
if (t == "object") {
|
|
162
|
-
//throw new Error("invalid type <Dictionary<string,string>>")
|
|
163
|
-
return "Dictionary<string,string>"
|
|
164
|
-
} else if (t == "object[]") {
|
|
165
|
-
//throw new Error("invalid type <Dictionary<string,string>[]>")
|
|
166
|
-
return "List<Dictionary<string,string>>"
|
|
167
|
-
} else if (t == "number") {
|
|
168
|
-
return "double";
|
|
169
|
-
} else if (t == "number[]") {
|
|
170
|
-
return "double[]";
|
|
171
|
-
} else if (t == "float") {
|
|
172
|
-
return "float";
|
|
173
|
-
} else if (t == "float[]") {
|
|
174
|
-
return "float[]";
|
|
175
|
-
} else if (t == "int") {
|
|
176
|
-
return "int";
|
|
177
|
-
} else if (t == "int[]") {
|
|
178
|
-
return "int[]";
|
|
179
|
-
} else if (t == "long") {
|
|
180
|
-
return "long";
|
|
181
|
-
} else if (t == "long[]") {
|
|
182
|
-
return "long[]";
|
|
183
|
-
} else if (t == "uid") {
|
|
184
|
-
return "int";
|
|
185
|
-
} else if (t == "bool") {
|
|
186
|
-
return "bool";
|
|
187
|
-
} else if (t == "bool[]") {
|
|
188
|
-
return "bool[]";
|
|
189
|
-
} else if (t == "string") {
|
|
190
|
-
return "string";
|
|
191
|
-
} else if (t == "string[]") {
|
|
192
|
-
return "string[]";
|
|
193
|
-
} else if (t == "fk") {
|
|
194
|
-
return "int";
|
|
195
|
-
} else if (t == "fk[]") {
|
|
196
|
-
return "int[]";
|
|
197
|
-
} else if (t == "any") {
|
|
198
|
-
console.log(f)
|
|
199
|
-
throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
|
|
200
|
-
} else if (t == "key") {
|
|
201
|
-
return "string";
|
|
202
|
-
} else {
|
|
203
|
-
throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
|
|
204
|
-
}
|
|
205
|
-
return t;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
let getFkFieldType = function (field: Field) {
|
|
209
|
-
return tables.find(a => a.name == field.fkTableName)!.fields!.find(a => a.name == field.fkFieldName)!.type
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const genValue = (value: any, f: Field): string => {
|
|
213
|
-
return ConvValue2Literal(value, f.type, f)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const getTitle = (v: Field) => {
|
|
217
|
-
return v.describe.split("\n")[0]
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const getDescripts = (v: Field) => {
|
|
221
|
-
return v.describe.split("\n")
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const convTupleArrayType = (f: Field) => {
|
|
225
|
-
let line0 = f.rawType.replaceAll(/(?<=[^\w])(number)(?=[^\w]|$)/g, "double").replaceAll(/(?<=[^\w])(boolean)(?=[^\w]|$)/g, "bool");
|
|
226
|
-
console.log(line0)
|
|
227
|
-
let m = line0.match(/\@\((\w+),(\w+)\)(\[\])?/)
|
|
228
|
-
if (m != null) {
|
|
229
|
-
let type1 = m[1]
|
|
230
|
-
let type2 = m[2]
|
|
231
|
-
let isArray = m[3] != null
|
|
232
|
-
let line = `public System.Tuple<${type1}, ${type2}>${isArray ? "[]" : ""} ${convMemberName(f.name)}Obj;`
|
|
233
|
-
return line;
|
|
234
|
-
} else {
|
|
235
|
-
return `public ${line0} ${convMemberName(f.name)}Obj;`
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
30
|
let temp = `
|
|
240
31
|
using System.Collections.Generic;
|
|
241
32
|
using System.Linq;
|
|
@@ -310,11 +101,12 @@ ${foreach(fields, f => {
|
|
|
310
101
|
${foreach(fields, f => {
|
|
311
102
|
if (f.isUnique) {
|
|
312
103
|
let memberName = convMemberName(f.name);
|
|
313
|
-
let
|
|
104
|
+
let paraName = convVarName(memberName);
|
|
105
|
+
let tempDictByMemberName = `TempDictBy${memberName}`;
|
|
314
106
|
let memberType = getFieldType(f);
|
|
315
107
|
return `
|
|
316
108
|
protected static Dictionary<${memberType}, ${RowClass}> ${tempDictByMemberName};
|
|
317
|
-
public static ${RowClass} GetConfigBy${memberName}(${memberType} ${
|
|
109
|
+
public static ${RowClass} GetConfigBy${memberName}(${memberType} ${paraName})
|
|
318
110
|
{
|
|
319
111
|
if (${tempDictByMemberName} == null)
|
|
320
112
|
{
|
|
@@ -331,18 +123,19 @@ ${foreach(fields, f => {
|
|
|
331
123
|
UnityEngine.Debug.LogError($"配表数据不一致(ConfigsUnmatched): {${tempDictByMemberName}.Count}!={Configs.Count}");
|
|
332
124
|
}
|
|
333
125
|
#endif
|
|
334
|
-
return ${tempDictByMemberName}.GetValueOrDefault(${
|
|
335
|
-
|
|
126
|
+
return ${tempDictByMemberName}.GetValueOrDefault(${paraName});
|
|
127
|
+
}
|
|
336
128
|
`
|
|
337
129
|
} else if (f.type == "number" || f.type == "float" || f.type == "int" || f.type == "long" || f.type == "string") {
|
|
338
130
|
let memberName = convMemberName(f.name);
|
|
339
|
-
let
|
|
131
|
+
let paraName = convVarName(memberName);
|
|
132
|
+
let tempRecordsDictByMemberName = `TempRecordsDictBy${memberName}`;
|
|
340
133
|
let memberType = getFieldType(f);
|
|
341
134
|
return `
|
|
342
135
|
protected static Dictionary<${memberType}, ${RowClass}[]> ${tempRecordsDictByMemberName};
|
|
343
|
-
public static ${RowClass}[] GetConfigsBy${memberName}(${memberType} ${
|
|
136
|
+
public static ${RowClass}[] GetConfigsBy${memberName}(${memberType} ${paraName})
|
|
344
137
|
{
|
|
345
|
-
if (${tempRecordsDictByMemberName} != null && ${tempRecordsDictByMemberName}.TryGetValue(${
|
|
138
|
+
if (${tempRecordsDictByMemberName} != null && ${tempRecordsDictByMemberName}.TryGetValue(${paraName},out var retValue))
|
|
346
139
|
{
|
|
347
140
|
return retValue;
|
|
348
141
|
}
|
|
@@ -352,8 +145,8 @@ ${foreach(fields, f => {
|
|
|
352
145
|
{
|
|
353
146
|
${tempRecordsDictByMemberName} = new Dictionary<${memberType}, ${RowClass}[]>(Configs.Count);
|
|
354
147
|
}
|
|
355
|
-
var records = Configs.Where(c => c.${memberName} == ${
|
|
356
|
-
${tempRecordsDictByMemberName}.Add(${
|
|
148
|
+
var records = Configs.Where(c => c.${memberName} == ${paraName}).ToArray();
|
|
149
|
+
${tempRecordsDictByMemberName}.Add(${paraName}, records);
|
|
357
150
|
return records;
|
|
358
151
|
}
|
|
359
152
|
}
|
|
@@ -369,7 +162,7 @@ ${foreach(fields, f => {
|
|
|
369
162
|
#region 生成fk.get/set
|
|
370
163
|
${foreach(fields, f => `
|
|
371
164
|
${iff(f.type == "fk", () => `
|
|
372
|
-
${iff(getFkFieldType(f).toLowerCase() != "uid", () => `
|
|
165
|
+
${iff(getFkFieldType(tables, f).toLowerCase() != "uid", () => `
|
|
373
166
|
protected ${convMemberName(f.fkTableName!)}[] _fk${convMemberName(f.name)}=null;
|
|
374
167
|
/**
|
|
375
168
|
* ${f.describe}
|