export-table-pulgin-csharp 1.0.43 → 1.0.44

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.
Files changed (50) hide show
  1. package/dist/ExportCSPlugin.d.ts.map +1 -1
  2. package/dist/ExportCSPlugin.js +160 -140
  3. package/package.json +25 -25
  4. package/src/ExportCSPlugin.ts +325 -311
  5. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/345/210/227/350/241/250.asset +15 -0
  6. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/345/210/227/350/241/250.cs +226 -0
  7. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/345/210/227/350/241/250Loader.cs +26 -0
  8. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/345/245/226/345/212/261.asset +15 -0
  9. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/345/245/226/345/212/261.cs +115 -0
  10. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/345/245/226/345/212/261Loader.cs +26 -0
  11. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/346/227/266/351/231/220.asset +15 -0
  12. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/346/227/266/351/231/220.cs +88 -0
  13. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/346/227/266/351/231/220Loader.cs +26 -0
  14. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/350/247/246/345/217/221/347/272/246/346/235/237/351/205/215/350/241/250.asset +15 -0
  15. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/350/247/246/345/217/221/347/272/246/346/235/237/351/205/215/350/241/250.cs +291 -0
  16. package/test/dist/EGBL/344/273/273/345/212/241/351/205/215/347/275/256-/344/273/273/345/212/241/350/247/246/345/217/221/347/272/246/346/235/237/351/205/215/350/241/250Loader.cs +26 -0
  17. package/test/dist/SceneConfig-SceneConfig.asset +15 -0
  18. package/test/dist/SceneConfig-SceneConfigLoader.cs +26 -0
  19. package/test/dist/SceneConfig-Sheet2.asset +15 -0
  20. package/test/dist/SceneConfig-Sheet2Loader.cs +26 -0
  21. package/test/dist/SceneConfig.cs +112 -55
  22. package/test/dist//345/257/271/350/257/235/350/241/250-/345/257/271/350/257/235/350/241/250.asset +15 -0
  23. package/test/dist//345/257/271/350/257/235/350/241/250-/345/257/271/350/257/235/350/241/250.cs +453 -0
  24. package/test/dist//345/257/271/350/257/235/350/241/250-/345/257/271/350/257/235/350/241/250Loader.cs +26 -0
  25. package/test/dist//350/277/207/345/234/272/345/274/225/345/257/274-/350/277/207/345/234/272/345/274/225/345/257/274.asset +15 -0
  26. package/test/dist//350/277/207/345/234/272/345/274/225/345/257/274-/350/277/207/345/234/272/345/274/225/345/257/274.cs +364 -0
  27. package/test/dist//350/277/207/345/234/272/345/274/225/345/257/274-/350/277/207/345/234/272/345/274/225/345/257/274Loader.cs +26 -0
  28. package/test/src/EGBL/344/273/273/345/212/241/351/205/215/347/275/256.xlsx +0 -0
  29. package/test/src/~$/345/257/271/350/257/235/350/241/250.xlsx +0 -0
  30. package/test/src//345/257/271/350/257/235/350/241/250.xlsx +0 -0
  31. package/test/src//350/277/207/345/234/272/345/274/225/345/257/274.xlsx +0 -0
  32. package/test/{test.bat → testCS.bat} +0 -0
  33. package/test/testUJson.bat +1 -0
  34. package/dist/launch.d.ts +0 -1
  35. package/dist/launch.js +0 -5
  36. package/dist/launch.js.map +0 -1
  37. package/dist//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250-unit.cs +0 -94
  38. package/dist//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250-unit/350/241/250.cs +0 -276
  39. package/dist//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250-/344/270/223/345/256/266/350/257/204/344/273/267.cs +0 -210
  40. package/dist//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250-/344/270/273/351/242/230/344/277/241/346/201/257/350/241/250.cs +0 -285
  41. package/dist//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250-/344/270/273/351/242/230/345/257/271/345/272/224unit.cs +0 -93
  42. package/dist//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250-/344/273/273/345/212/241/345/260/217/347/273/223.cs +0 -141
  43. package/dist//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250-/344/273/273/345/212/241/350/241/250.cs +0 -151
  44. package/dist//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250-/344/273/273/345/212/241/350/247/246/345/217/221/350/241/250.cs +0 -111
  45. package/quicktable//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250.xlsx +0 -0
  46. package/src//350/257/276/347/250/213/344/277/241/346/201/257/350/241/250.xlsx +0 -0
  47. package/test/dist/SceneConfig.csharp +0 -0
  48. package/test/dist/SceneConfig.csx +0 -55
  49. package/test/dist/Sheet2.csharp +0 -0
  50. package/test/dist/table.csharp +0 -0
@@ -1,311 +1,325 @@
1
-
2
- import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, iff } from "export-table-lib"
3
- import * as fs from "fs-extra"
4
- import { json } from "stream/consumers";
5
-
6
- export function export_stuff(paras: HandleSheetParams): string | null {
7
- let {
8
- datas,
9
- fields,
10
- inject,
11
- name,
12
- objects,
13
- packagename,
14
- tables,
15
- xxtea,
16
- } = paras;
17
-
18
- let firstLetterUpper = function (str: string) {
19
- return str.charAt(0).toUpperCase() + str.slice(1);
20
- };
21
- let firstLetterLower = function (str: string) {
22
- return str.charAt(0).toLowerCase() + str.slice(1);
23
- };
24
- let convMemberName = function (str: string) {
25
- return str.split("_").map(s => firstLetterUpper(s)).join("")
26
- }
27
- let convVarName = firstLetterLower
28
-
29
- let RowClass = firstLetterUpper(name)
30
- let initFunc = name + "Init"
31
- let mapfield = fields.find(a => a.type == "key")//如果是map,则生成对应的map
32
- let mapName = name + "Map"
33
-
34
- let getFieldType = function (f: Field) {
35
- let t = f.type
36
- if (t == "object") {
37
- //throw new Error("invalid type <Dictionary<string,string>>")
38
- return "Dictionary<string,string>"
39
- } else if (t == "object[]") {
40
- //throw new Error("invalid type <Dictionary<string,string>[]>")
41
- return "List<Dictionary<string,string>>"
42
- } else if (t == "number") {
43
- return "double";
44
- } else if (t == "number[]") {
45
- return "double[]";
46
- } else if (t == "uid") {
47
- return "int";
48
- } else if (t == "bool") {
49
- return "bool";
50
- } else if (t == "bool[]") {
51
- return "bool[]";
52
- } else if (t == "string") {
53
- return "string";
54
- } else if (t == "string[]") {
55
- return "string[]";
56
- } else if (t == "fk") {
57
- return "int";
58
- } else if (t == "fk[]") {
59
- return "int[]";
60
- } else if (t == "any") {
61
- console.log(f)
62
- throw new Error(`invalid type ${f.name}:<any>`)
63
- } else if (t == "key") {
64
- return "string";
65
- } else {
66
- throw new Error(`invalid type ${f.name}:<unkown>`)
67
- }
68
- return t;
69
- }
70
-
71
- let getFkFieldType = function (field: Field) {
72
- return tables.find(a => a.name == field.fkTableName)!.fields!.find(a => a.name == field.fkFieldName)!.type
73
- }
74
-
75
- const genValue = (value: any, f: Field): string => {
76
- let t = f.type
77
- if (t == "object") {
78
- //throw new Error("invalid type <object>")
79
- let convert:string[] = [];
80
- for (let k in value) {
81
- convert.push(`{"${k}","${(value as any)[k].toString()}"}`);
82
- };
83
- return `new Dictionary<string,string>(){${convert}}`;
84
- } else if (t == "object[]") {
85
- let values = value as object[];
86
- //throw new Error("invalid type <object[]>")
87
- return `new List<Dictionary<string,string>>(){${values.map((val)=>{
88
- let convert:string[] = [];
89
- for (let k in val) {
90
- convert.push(`{"${k}","${(val as any)[k].toString()}"}`);
91
- };
92
- return `new Dictionary<string,string>(){${convert}}`;
93
- })}}`
94
- } else if (t == "number") {
95
- return `${value}`
96
- } else if (t == "number[]") {
97
- let values = value as number[]
98
- return `new double[]{${values.join(", ")}}`
99
- } else if (t == "uid") {
100
- return `${value}`
101
- } else if (t == "bool") {
102
- return `${value}`
103
- } else if (t == "bool[]") {
104
- let values = value as boolean[]
105
- return `new bool[]{${values.join(", ")}}`
106
- } else if (t == "string") {
107
- // return `"${value}"`
108
- return JSON.stringify(value)
109
- } else if (t == "string[]") {
110
- let values = value as string[]
111
- return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`
112
- } else if (t == "fk") {
113
- return `${value}`
114
- } else if (t == "fk[]") {
115
- let values = value as number[]
116
- return `new int[]{${values.join(", ")}}`
117
- } else if (t == "any") {
118
- console.log(f)
119
- throw new Error(`invalid type ${f.name}:<any>`)
120
- } else if (t == "key") {
121
- return `${value}`
122
- }
123
-
124
- throw new Error(`invalid type ${f.name}:<unkown>`)
125
- }
126
-
127
- const getTitle = (v: Field) => {
128
- return v.describe.split("\n")[0]
129
- }
130
-
131
- const getDescripts = (v: Field) => {
132
- return v.describe.split("\n")
133
- }
134
-
135
- let temp = `
136
- using System.Collections.Generic;
137
- using System.Linq;
138
-
139
- namespace MEEC.ExportedConfigs{
140
- public partial class ${RowClass} {
141
-
142
- public static List<${RowClass}> Configs = new List<${RowClass}>()
143
- {
144
- ${foreach(datas, data =>
145
- ` new ${RowClass}(${st(() => fields.map((f, index) => genValue(data[index], f)).join(", "))}),`
146
- )}
147
- };
148
-
149
- public ${RowClass}() { }
150
- public ${RowClass}(${st(() => fields.map(f => `${getFieldType(f)} ${convVarName(f.name)}`).join(", "))})
151
- {
152
- ${foreach(fields, f =>
153
- ` this.${convMemberName(f.name)} = ${convVarName(f.name)};`
154
- )}
155
- }
156
-
157
- public virtual ${RowClass} MergeFrom(${RowClass} source)
158
- {
159
- ${foreach(fields, f =>
160
- ` this.${convMemberName(f.name)} = source.${convMemberName(f.name)};`
161
- )}
162
- return this;
163
- }
164
-
165
- public virtual ${RowClass} Clone()
166
- {
167
- var config = new ${RowClass}();
168
- config.MergeFrom(this);
169
- return config;
170
- }
171
-
172
- ${cmm(/**生成字段 */)}
173
- ${foreach(fields, f => `
174
- /// <summary>
175
- ${foreach(getDescripts(f), line =>
176
- ` /// ${line}`
177
- )}
178
- /// </summary>
179
- public ${getFieldType(f)} ${convMemberName(f.name)};`
180
- )}
181
-
182
- ${cmm(/**生成get字段 */)}
183
- #region get字段
184
- ${foreach(fields, f => {
185
- if (f.nameOrigin != f.name) {
186
- return ` public ${getFieldType(f)} ${getTitle(f).replace(" ", "_")} => ${convMemberName(f.name)};`
187
- } else {
188
- return ""
189
- }
190
- }
191
- )}
192
- #endregion
193
-
194
- #region uid map
195
- ${foreach(fields, f => {
196
- if (f.isUnique) {
197
- return `
198
- protected static Dictionary<${getFieldType(f)}, ${RowClass}> _tempDictBy${convMemberName(f.name)};
199
- public static ${RowClass} GetConfigBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
200
- {
201
- if (_tempDictBy${convMemberName(f.name)} == null)
202
- {
203
- _tempDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}>();
204
- Configs.ForEach(c =>
205
- {
206
- _tempDictBy${convMemberName(f.name)}.Add(c.${convMemberName(f.name)}, c);
207
- });
208
- }
209
- return _tempDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
210
- }
211
- `
212
- } else if (f.type == "number" || f.type == "string") {
213
- return `
214
- protected static Dictionary<${getFieldType(f)}, ${RowClass}[]> _tempRecordsDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}[]>();
215
- public static ${RowClass}[] GetConfigsBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
216
- {
217
- if (_tempRecordsDictBy${convMemberName(f.name)}.ContainsKey(${convMemberName(f.name)}))
218
- {
219
- return _tempRecordsDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
220
- }
221
- else
222
- {
223
- var records = Configs.Where(c => c.${convMemberName(f.name)} == ${convMemberName(f.name)}).ToArray();
224
- _tempRecordsDictBy${convMemberName(f.name)}.Add(${convMemberName(f.name)}, records);
225
- return records;
226
- }
227
- }
228
- `
229
- } else {
230
- return ""
231
- }
232
- }
233
- )}
234
-
235
- #endregion uid map
236
-
237
- #region 生成fk.get/set
238
- ${foreach(fields, f => `
239
- ${iff(f.type == "fk", () => `
240
- ${iff(getFkFieldType(f).toLowerCase() != "uid", () => `
241
- protected ${convMemberName(f.fkTableName!)}[] _fk${convMemberName(f.name)}=null;
242
- /**
243
- * ${f.describe}
244
- **/
245
- public virtual ${convMemberName(f.fkTableName!)}[] ${convMemberName(f.name)}DataList{
246
- get{
247
- if(this._fk${convMemberName(f.name)}==null){
248
- if(null==this.${convMemberName(f.name)}){
249
- this._fk${convMemberName(f.name)} = new ${convMemberName(f.fkTableName!)}[0];
250
- }else{
251
- this._fk${convMemberName(f.name)}=${convMemberName(f.fkTableName!)}.FindAll(a=>a.${convMemberName(f.fkFieldName!)}!=null && this.${convMemberName(f.name)}==a.${convMemberName(f.fkFieldName!)}).ToArray();
252
- }
253
- }
254
- return this._fk${convMemberName(f.name)};
255
- }
256
- }
257
- `).else(() => `
258
- protected ${convMemberName(f.fkTableName!)} _fk${convMemberName(f.name)}=null;
259
- /**
260
- * ${f.describe}
261
- **/
262
- public virtual ${convMemberName(f.fkTableName!)} ${convMemberName(f.name)}Data{
263
- get{
264
- if(this._fk${convMemberName(f.name)}==null){
265
- this._fk${convMemberName(f.name)}=${convMemberName(f.fkTableName!)}.Find(a=>a.${convMemberName(f.fkFieldName!)}==this.${convMemberName(f.name)});
266
- }
267
- return this._fk${convMemberName(f.name)};
268
- }
269
- }
270
- `)}
271
- `)}
272
- ${iff(f.type == "fk[]", () => `
273
- protected ${convMemberName(f.fkTableName!)}[] _fk${convMemberName(f.name)}=null;
274
- /**
275
- * ${f.describe}
276
- **/
277
- public virtual ${convMemberName(f.fkTableName!)}[] ${convMemberName(f.name)}DataList{
278
- get{
279
- if(this._fk${convMemberName(f.name)}==null){
280
- if(null==this.${convMemberName(f.name)}){
281
- this._fk${convMemberName(f.name)} = new ${convMemberName(f.fkTableName!)}[0];
282
- }else{
283
- this._fk${convMemberName(f.name)}=MEEC.ExportedConfigs.${convMemberName(f.fkTableName!)}.Configs.FindAll(a=>a.${convMemberName(f.fkFieldName!)}!=null && this.${convMemberName(f.name)}!.Contains(a.${convMemberName(f.fkFieldName!)})).ToArray();
284
- }
285
- }
286
- return this._fk${convMemberName(f.name)};
287
- }
288
- }
289
- `)}
290
- `)}
291
- #endregion 生成fk.get/set
292
- }
293
- }
294
- `
295
-
296
- return temp
297
-
298
- }
299
-
300
- export class ExportPlugin extends PluginBase {
301
- name = "csharp"
302
- tags: string[] = ["cs"]
303
-
304
- handleSheet(paras: HandleSheetParams) {
305
- let content = export_stuff(paras)
306
- if (content != null) {
307
- fs.outputFileSync(paras.outFilePath.fullPath, content, "utf-8")
308
- }
309
- return content
310
- }
311
- }
1
+
2
+ import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, iff } from "export-table-lib"
3
+ import * as fs from "fs-extra"
4
+ import { json } from "stream/consumers";
5
+
6
+ export function export_stuff(paras: HandleSheetParams): string | null {
7
+ let {
8
+ datas,
9
+ fields,
10
+ inject,
11
+ name,
12
+ objects,
13
+ packagename,
14
+ tables,
15
+ xxtea,
16
+ } = paras;
17
+
18
+ let firstLetterUpper = function (str: string) {
19
+ return str.charAt(0).toUpperCase() + str.slice(1);
20
+ };
21
+ let firstLetterLower = function (str: string) {
22
+ return str.charAt(0).toLowerCase() + str.slice(1);
23
+ };
24
+ let convMemberName = function (str: string) {
25
+ return str.split("_").map(s => firstLetterUpper(s)).join("")
26
+ }
27
+ let convVarName = firstLetterLower
28
+
29
+ let RowClass = firstLetterUpper(name)
30
+ let initFunc = name + "Init"
31
+ let mapfield = fields.find(a => a.type == "key")//如果是map,则生成对应的map
32
+ let mapName = name + "Map"
33
+
34
+ let getFieldType = function (f: Field) {
35
+ let t = f.type
36
+ if (t == "object") {
37
+ //throw new Error("invalid type <Dictionary<string,string>>")
38
+ return "Dictionary<string,string>"
39
+ } else if (t == "object[]") {
40
+ //throw new Error("invalid type <Dictionary<string,string>[]>")
41
+ return "List<Dictionary<string,string>>"
42
+ } else if (t == "number") {
43
+ return "double";
44
+ } else if (t == "number[]") {
45
+ return "double[]";
46
+ } else if (t == "int") {
47
+ return "int";
48
+ } else if (t == "int[]") {
49
+ return "int[]";
50
+ } else if (t == "long") {
51
+ return "long";
52
+ } else if (t == "long[]") {
53
+ return "long[]";
54
+ } else if (t == "uid") {
55
+ return "int";
56
+ } else if (t == "bool") {
57
+ return "bool";
58
+ } else if (t == "bool[]") {
59
+ return "bool[]";
60
+ } else if (t == "string") {
61
+ return "string";
62
+ } else if (t == "string[]") {
63
+ return "string[]";
64
+ } else if (t == "fk") {
65
+ return "int";
66
+ } else if (t == "fk[]") {
67
+ return "int[]";
68
+ } else if (t == "any") {
69
+ console.log(f)
70
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
71
+ } else if (t == "key") {
72
+ return "string";
73
+ } else {
74
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
75
+ }
76
+ return t;
77
+ }
78
+
79
+ let getFkFieldType = function (field: Field) {
80
+ return tables.find(a => a.name == field.fkTableName)!.fields!.find(a => a.name == field.fkFieldName)!.type
81
+ }
82
+
83
+ const genValue = (value: any, f: Field): string => {
84
+ let t = f.type
85
+ if (t == "object") {
86
+ //throw new Error("invalid type <object>")
87
+ let convert: string[] = [];
88
+ for (let k in value) {
89
+ convert.push(`{"${k}","${(value as any)[k].toString()}"}`);
90
+ };
91
+ return `new Dictionary<string,string>(){${convert}}`;
92
+ } else if (t == "object[]") {
93
+ let values = value as object[];
94
+ //throw new Error("invalid type <object[]>")
95
+ return `new List<Dictionary<string,string>>(){${values.map((val) => {
96
+ let convert: string[] = [];
97
+ for (let k in val) {
98
+ convert.push(`{"${k}","${(val as any)[k].toString()}"}`);
99
+ };
100
+ return `new Dictionary<string,string>(){${convert}}`;
101
+ })}}`
102
+ } else if (t == "number" || t == "int" || t == "long") {
103
+ return `${value}`
104
+ } else if (t == "number[]") {
105
+ let values = value as number[]
106
+ return `new double[]{${values.join(", ")}}`
107
+ } else if (t == "int[]") {
108
+ let values = value as number[]
109
+ return `new int[]{${values.join(", ")}}`
110
+ } else if (t == "long[]") {
111
+ let values = value as number[]
112
+ return `new long[]{${values.join(", ")}}`
113
+ } else if (t == "uid") {
114
+ return `${value}`
115
+ } else if (t == "bool") {
116
+ return `${value}`
117
+ } else if (t == "bool[]") {
118
+ let values = value as boolean[]
119
+ return `new bool[]{${values.join(", ")}}`
120
+ } else if (t == "string") {
121
+ // return `"${value}"`
122
+ return JSON.stringify(value)
123
+ } else if (t == "string[]") {
124
+ let values = value as string[]
125
+ return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`
126
+ } else if (t == "fk") {
127
+ return `${value}`
128
+ } else if (t == "fk[]") {
129
+ let values = value as number[]
130
+ return `new int[]{${values.join(", ")}}`
131
+ } else if (t == "any") {
132
+ console.log(f)
133
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
134
+ } else if (t == "key") {
135
+ return `${value}`
136
+ }
137
+
138
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
139
+ }
140
+
141
+ const getTitle = (v: Field) => {
142
+ return v.describe.split("\n")[0]
143
+ }
144
+
145
+ const getDescripts = (v: Field) => {
146
+ return v.describe.split("\n")
147
+ }
148
+
149
+ let temp = `
150
+ using System.Collections.Generic;
151
+ using System.Linq;
152
+
153
+ namespace MEEC.ExportedConfigs{
154
+ public partial class ${RowClass} {
155
+
156
+ public static List<${RowClass}> Configs = new List<${RowClass}>()
157
+ {
158
+ ${foreach(datas, data =>
159
+ ` new ${RowClass}(${st(() => fields.map((f, index) => genValue(data[index], f)).join(", "))}),`
160
+ )}
161
+ };
162
+
163
+ public ${RowClass}() { }
164
+ public ${RowClass}(${st(() => fields.map(f => `${getFieldType(f)} ${convVarName(f.name)}`).join(", "))})
165
+ {
166
+ ${foreach(fields, f =>
167
+ ` this.${convMemberName(f.name)} = ${convVarName(f.name)};`
168
+ )}
169
+ }
170
+
171
+ public virtual ${RowClass} MergeFrom(${RowClass} source)
172
+ {
173
+ ${foreach(fields, f =>
174
+ ` this.${convMemberName(f.name)} = source.${convMemberName(f.name)};`
175
+ )}
176
+ return this;
177
+ }
178
+
179
+ public virtual ${RowClass} Clone()
180
+ {
181
+ var config = new ${RowClass}();
182
+ config.MergeFrom(this);
183
+ return config;
184
+ }
185
+
186
+ ${cmm(/**生成字段 */)}
187
+ ${foreach(fields, f => `
188
+ /// <summary>
189
+ ${foreach(getDescripts(f), line =>
190
+ ` /// ${line}`
191
+ )}
192
+ /// </summary>
193
+ public ${getFieldType(f)} ${convMemberName(f.name)};`
194
+ )}
195
+
196
+ ${cmm(/**生成get字段 */)}
197
+ #region get字段
198
+ ${foreach(fields, f => {
199
+ if (f.nameOrigin != f.name) {
200
+ return ` public ${getFieldType(f)} ${getTitle(f).replace(" ", "_")} => ${convMemberName(f.name)};`
201
+ } else {
202
+ return ""
203
+ }
204
+ }
205
+ )}
206
+ #endregion
207
+
208
+ #region uid map
209
+ ${foreach(fields, f => {
210
+ if (f.isUnique) {
211
+ return `
212
+ protected static Dictionary<${getFieldType(f)}, ${RowClass}> _tempDictBy${convMemberName(f.name)};
213
+ public static ${RowClass} GetConfigBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
214
+ {
215
+ if (_tempDictBy${convMemberName(f.name)} == null)
216
+ {
217
+ _tempDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}>();
218
+ Configs.ForEach(c =>
219
+ {
220
+ _tempDictBy${convMemberName(f.name)}.Add(c.${convMemberName(f.name)}, c);
221
+ });
222
+ }
223
+ return _tempDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
224
+ }
225
+ `
226
+ } else if (f.type == "number" || f.type == "int" || f.type == "long" || f.type == "string") {
227
+ return `
228
+ protected static Dictionary<${getFieldType(f)}, ${RowClass}[]> _tempRecordsDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}[]>();
229
+ public static ${RowClass}[] GetConfigsBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
230
+ {
231
+ if (_tempRecordsDictBy${convMemberName(f.name)}.ContainsKey(${convMemberName(f.name)}))
232
+ {
233
+ return _tempRecordsDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
234
+ }
235
+ else
236
+ {
237
+ var records = Configs.Where(c => c.${convMemberName(f.name)} == ${convMemberName(f.name)}).ToArray();
238
+ _tempRecordsDictBy${convMemberName(f.name)}.Add(${convMemberName(f.name)}, records);
239
+ return records;
240
+ }
241
+ }
242
+ `
243
+ } else {
244
+ return ""
245
+ }
246
+ }
247
+ )}
248
+
249
+ #endregion uid map
250
+
251
+ #region 生成fk.get/set
252
+ ${foreach(fields, f => `
253
+ ${iff(f.type == "fk", () => `
254
+ ${iff(getFkFieldType(f).toLowerCase() != "uid", () => `
255
+ protected ${convMemberName(f.fkTableName!)}[] _fk${convMemberName(f.name)}=null;
256
+ /**
257
+ * ${f.describe}
258
+ **/
259
+ public virtual ${convMemberName(f.fkTableName!)}[] ${convMemberName(f.name)}DataList{
260
+ get{
261
+ if(this._fk${convMemberName(f.name)}==null){
262
+ if(null==this.${convMemberName(f.name)}){
263
+ this._fk${convMemberName(f.name)} = new ${convMemberName(f.fkTableName!)}[0];
264
+ }else{
265
+ this._fk${convMemberName(f.name)}=${convMemberName(f.fkTableName!)}.FindAll(a=>a.${convMemberName(f.fkFieldName!)}!=null && this.${convMemberName(f.name)}==a.${convMemberName(f.fkFieldName!)}).ToArray();
266
+ }
267
+ }
268
+ return this._fk${convMemberName(f.name)};
269
+ }
270
+ }
271
+ `).else(() => `
272
+ protected ${convMemberName(f.fkTableName!)} _fk${convMemberName(f.name)}=null;
273
+ /**
274
+ * ${f.describe}
275
+ **/
276
+ public virtual ${convMemberName(f.fkTableName!)} ${convMemberName(f.name)}Data{
277
+ get{
278
+ if(this._fk${convMemberName(f.name)}==null){
279
+ this._fk${convMemberName(f.name)}=${convMemberName(f.fkTableName!)}.Find(a=>a.${convMemberName(f.fkFieldName!)}==this.${convMemberName(f.name)});
280
+ }
281
+ return this._fk${convMemberName(f.name)};
282
+ }
283
+ }
284
+ `)}
285
+ `)}
286
+ ${iff(f.type == "fk[]", () => `
287
+ protected ${convMemberName(f.fkTableName!)}[] _fk${convMemberName(f.name)}=null;
288
+ /**
289
+ * ${f.describe}
290
+ **/
291
+ public virtual ${convMemberName(f.fkTableName!)}[] ${convMemberName(f.name)}DataList{
292
+ get{
293
+ if(this._fk${convMemberName(f.name)}==null){
294
+ if(null==this.${convMemberName(f.name)}){
295
+ this._fk${convMemberName(f.name)} = new ${convMemberName(f.fkTableName!)}[0];
296
+ }else{
297
+ this._fk${convMemberName(f.name)}=MEEC.ExportedConfigs.${convMemberName(f.fkTableName!)}.Configs.FindAll(a=>a.${convMemberName(f.fkFieldName!)}!=null && this.${convMemberName(f.name)}!.Contains(a.${convMemberName(f.fkFieldName!)})).ToArray();
298
+ }
299
+ }
300
+ return this._fk${convMemberName(f.name)};
301
+ }
302
+ }
303
+ `)}
304
+ `)}
305
+ #endregion 生成fk.get/set
306
+ }
307
+ }
308
+ `
309
+
310
+ return temp
311
+
312
+ }
313
+
314
+ export class ExportPlugin extends PluginBase {
315
+ name = "csharp"
316
+ tags: string[] = ["cs"]
317
+
318
+ handleSheet(paras: HandleSheetParams) {
319
+ let content = export_stuff(paras)
320
+ if (content != null) {
321
+ fs.outputFileSync(paras.outFilePath.fullPath, content, "utf-8")
322
+ }
323
+ return content
324
+ }
325
+ }