export-table-pulgin-csharp 1.1.84 → 1.1.86

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.
@@ -1,4 +1,7 @@
1
- import { HandleSheetParams, PluginBase } from "export-table-lib";
1
+ import { HandleSheetParams, Field, PluginBase, FieldType } from "export-table-lib";
2
+ export declare function TryConvValue(value: any, t: FieldType, f: Field): any;
3
+ export declare function ConvValue(value: any, t: FieldType, f: Field): any;
4
+ export declare function ConvValue2Literal(value: any, t: FieldType, f: Field): string;
2
5
  export declare function export_stuff(paras: HandleSheetParams): string | null;
3
6
  export declare class ExportPlugin extends PluginBase {
4
7
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ExportCSPlugin.d.ts","sourceRoot":"","sources":["../src/ExportCSPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAA0B,MAAM,kBAAkB,CAAA;AAK1H,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CA6UpE;AAED,qBAAa,YAAa,SAAQ,UAAU;IAC3C,IAAI,SAAW;IACf,IAAI,EAAE,MAAM,EAAE,CAAS;IAEvB,WAAW,CAAC,KAAK,EAAE,iBAAiB;CAOpC"}
1
+ {"version":3,"file":"ExportCSPlugin.d.ts","sourceRoot":"","sources":["../src/ExportCSPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAAE,KAAK,EAAwB,UAAU,EAA0B,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGrI,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG,GAAG,CAMpE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG,GAAG,CAwCjE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG,MAAM,CAuD5E;AAID,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CA+RpE;AAED,qBAAa,YAAa,SAAQ,UAAU;IAC3C,IAAI,SAAW;IACf,IAAI,EAAE,MAAM,EAAE,CAAS;IAEvB,WAAW,CAAC,KAAK,EAAE,iBAAiB;CAOpC"}
@@ -23,14 +23,150 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ExportPlugin = exports.export_stuff = void 0;
26
+ exports.ExportPlugin = exports.export_stuff = exports.ConvValue2Literal = exports.ConvValue = exports.TryConvValue = void 0;
27
27
  const export_table_lib_1 = require("export-table-lib");
28
28
  const fs = __importStar(require("fs-extra"));
29
+ function TryConvValue(value, t, f) {
30
+ try {
31
+ return ConvValue(value, t, f);
32
+ }
33
+ catch (ex) {
34
+ return null;
35
+ }
36
+ }
37
+ exports.TryConvValue = TryConvValue;
38
+ function ConvValue(value, t, f) {
39
+ if (t == "object") {
40
+ return JSON.parse(value);
41
+ }
42
+ else if (t == "object[]") {
43
+ return JSON.parse(value);
44
+ }
45
+ else if (t == "number" || t == "int" || t == "long") {
46
+ return JSON.parse(value);
47
+ }
48
+ else if (t == "number[]") {
49
+ return JSON.parse(value);
50
+ }
51
+ else if (t == "int[]") {
52
+ return JSON.parse(value);
53
+ }
54
+ else if (t == "long[]") {
55
+ return JSON.parse(value);
56
+ }
57
+ else if (t == "uid") {
58
+ return JSON.parse(value);
59
+ }
60
+ else if (t == "bool") {
61
+ try {
62
+ return !!JSON.parse(value);
63
+ }
64
+ catch (ex) {
65
+ console.log(ex);
66
+ return false;
67
+ }
68
+ }
69
+ else if (t == "bool[]") {
70
+ return JSON.parse(value);
71
+ }
72
+ else if (t == "string") {
73
+ return value;
74
+ }
75
+ else if (t == "string[]") {
76
+ return JSON.parse(value);
77
+ }
78
+ else if (t == "fk") {
79
+ return value;
80
+ }
81
+ else if (t == "fk[]") {
82
+ return value;
83
+ }
84
+ else if (t == "any") {
85
+ console.log(f);
86
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`);
87
+ }
88
+ else if (t == "key") {
89
+ return JSON.parse(t);
90
+ }
91
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`);
92
+ }
93
+ exports.ConvValue = ConvValue;
94
+ function ConvValue2Literal(value, t, f) {
95
+ if (t == "object") {
96
+ //throw new Error("invalid type <object>")
97
+ let convert = [];
98
+ for (let k in value) {
99
+ convert.push(`{"${k}","${value[k].toString()}"}`);
100
+ }
101
+ ;
102
+ return `new Dictionary<string,string>(${convert.length}){${convert}}`;
103
+ }
104
+ else if (t == "object[]") {
105
+ let values = value;
106
+ //throw new Error("invalid type <object[]>")
107
+ return `new List<Dictionary<string,string>>(){${values.map((val) => {
108
+ let convert = [];
109
+ for (let k in val) {
110
+ convert.push(`{"${k}","${val[k].toString()}"}`);
111
+ }
112
+ ;
113
+ return `new Dictionary<string,string>(${convert.length}){${convert}}`;
114
+ })}}`;
115
+ }
116
+ else if (t == "number" || t == "int" || t == "long") {
117
+ return `${value}`;
118
+ }
119
+ else if (t == "number[]") {
120
+ let values = value;
121
+ return `new double[]{${values.join(", ")}}`;
122
+ }
123
+ else if (t == "int[]") {
124
+ let values = value;
125
+ return `new int[]{${values.join(", ")}}`;
126
+ }
127
+ else if (t == "long[]") {
128
+ let values = value;
129
+ return `new long[]{${values.join(", ")}}`;
130
+ }
131
+ else if (t == "uid") {
132
+ return `${value}`;
133
+ }
134
+ else if (t == "bool") {
135
+ return `${value}`;
136
+ }
137
+ else if (t == "bool[]") {
138
+ let values = value;
139
+ return `new bool[]{${values.join(", ")}}`;
140
+ }
141
+ else if (t == "string") {
142
+ // return `"${value}"`
143
+ return JSON.stringify(value);
144
+ }
145
+ else if (t == "string[]") {
146
+ let values = value;
147
+ return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`;
148
+ }
149
+ else if (t == "fk") {
150
+ return `${value}`;
151
+ }
152
+ else if (t == "fk[]") {
153
+ let values = value;
154
+ return `new int[]{${values.join(", ")}}`;
155
+ }
156
+ else if (t == "any") {
157
+ console.log(f);
158
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`);
159
+ }
160
+ else if (t == "key") {
161
+ return `${value}`;
162
+ }
163
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`);
164
+ }
165
+ exports.ConvValue2Literal = ConvValue2Literal;
29
166
  var isSkipExportDefaults0 = process.argv.findIndex(v => v == "--SkipDefaults") >= 0;
30
167
  function export_stuff(paras) {
31
- var _a;
32
168
  let { datas, fields, inject, name, objects, packagename, tables, xxtea, exportNamespace, moreOptions, } = paras;
33
- let isSkipExportDefaults = (_a = !!moreOptions.SkipDefaults) !== null && _a !== void 0 ? _a : false;
169
+ let isSkipExportDefaults = !!moreOptions?.SkipDefaults ?? false;
34
170
  if (isSkipExportDefaults0) {
35
171
  isSkipExportDefaults = true;
36
172
  }
@@ -113,76 +249,7 @@ function export_stuff(paras) {
113
249
  return tables.find(a => a.name == field.fkTableName).fields.find(a => a.name == field.fkFieldName).type;
114
250
  };
115
251
  const genValue = (value, f) => {
116
- let t = f.type;
117
- if (t == "object") {
118
- //throw new Error("invalid type <object>")
119
- let convert = [];
120
- for (let k in value) {
121
- convert.push(`{"${k}","${value[k].toString()}"}`);
122
- }
123
- ;
124
- return `new Dictionary<string,string>(${convert.length}){${convert}}`;
125
- }
126
- else if (t == "object[]") {
127
- let values = value;
128
- //throw new Error("invalid type <object[]>")
129
- return `new List<Dictionary<string,string>>(){${values.map((val) => {
130
- let convert = [];
131
- for (let k in val) {
132
- convert.push(`{"${k}","${val[k].toString()}"}`);
133
- }
134
- ;
135
- return `new Dictionary<string,string>(${convert.length}){${convert}}`;
136
- })}}`;
137
- }
138
- else if (t == "number" || t == "int" || t == "long") {
139
- return `${value}`;
140
- }
141
- else if (t == "number[]") {
142
- let values = value;
143
- return `new double[]{${values.join(", ")}}`;
144
- }
145
- else if (t == "int[]") {
146
- let values = value;
147
- return `new int[]{${values.join(", ")}}`;
148
- }
149
- else if (t == "long[]") {
150
- let values = value;
151
- return `new long[]{${values.join(", ")}}`;
152
- }
153
- else if (t == "uid") {
154
- return `${value}`;
155
- }
156
- else if (t == "bool") {
157
- return `${value}`;
158
- }
159
- else if (t == "bool[]") {
160
- let values = value;
161
- return `new bool[]{${values.join(", ")}}`;
162
- }
163
- else if (t == "string") {
164
- // return `"${value}"`
165
- return JSON.stringify(value);
166
- }
167
- else if (t == "string[]") {
168
- let values = value;
169
- return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`;
170
- }
171
- else if (t == "fk") {
172
- return `${value}`;
173
- }
174
- else if (t == "fk[]") {
175
- let values = value;
176
- return `new int[]{${values.join(", ")}}`;
177
- }
178
- else if (t == "any") {
179
- console.log(f);
180
- throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`);
181
- }
182
- else if (t == "key") {
183
- return `${value}`;
184
- }
185
- throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`);
252
+ return ConvValue2Literal(value, f.type, f);
186
253
  };
187
254
  const getTitle = (v) => {
188
255
  return v.describe.split("\n")[0];
@@ -229,7 +296,13 @@ ${(0, export_table_lib_1.foreach)(fields, f => `
229
296
  /// <summary>
230
297
  ${(0, export_table_lib_1.foreach)(getDescripts(f), line => ` /// ${line}`)}
231
298
  /// </summary>
232
- public ${getFieldType(f)} ${convMemberName(f.name)};`)}
299
+ public ${getFieldType(f)} ${convMemberName(f.name)};
300
+
301
+ ${(0, export_table_lib_1.iff)(f.rawType.startsWith("@"), () => `
302
+ /// <summary>
303
+ ${(0, export_table_lib_1.foreach)(getDescripts(f), line => ` /// ${line}`)}
304
+ /// </summary>
305
+ public ${f.rawType.replaceAll(/(?<=[^\w])(number)(?=[^\w]|$)/g, "double").replaceAll(/(?<=[^\w])(boolean)(?=[^\w]|$)/g, "bool")} ${convMemberName(f.name)}Obj;`)}`)}
233
306
 
234
307
  ${(0, export_table_lib_1.cmm)( /**生成get字段 */)}
235
308
  #region get字段
@@ -366,11 +439,8 @@ ${(0, export_table_lib_1.iff)(f.type == "fk[]", () => `
366
439
  }
367
440
  exports.export_stuff = export_stuff;
368
441
  class ExportPlugin extends export_table_lib_1.PluginBase {
369
- constructor() {
370
- super(...arguments);
371
- this.name = "csharp";
372
- this.tags = ["cs"];
373
- }
442
+ name = "csharp";
443
+ tags = ["cs"];
374
444
  handleSheet(paras) {
375
445
  let content = export_stuff(paras);
376
446
  if (content != null) {
@@ -1 +1 @@
1
- {"version":3,"file":"ExportUnityCSJsonPlugin.d.ts","sourceRoot":"","sources":["../src/ExportUnityCSJsonPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAAE,iBAAiB,EAAqC,MAAM,kBAAkB,CAAA;AAMxJ,wBAAgB,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CA+CnE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAuFzE;AAED,qBAAa,iBAAkB,SAAQ,UAAU;IAChD,IAAI,SAAU;IACd,IAAI,EAAE,MAAM,EAAE,CAAY;IAE1B,WAAW,CAAC,KAAK,EAAE,iBAAiB;IAmBpC,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;CAmC3C"}
1
+ {"version":3,"file":"ExportUnityCSJsonPlugin.d.ts","sourceRoot":"","sources":["../src/ExportUnityCSJsonPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAAE,iBAAiB,EAAqC,MAAM,kBAAkB,CAAA;AAOxJ,wBAAgB,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAiFnE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAuFzE;AAED,qBAAa,iBAAkB,SAAQ,UAAU;IAChD,IAAI,SAAU;IACd,IAAI,EAAE,MAAM,EAAE,CAAY;IAE1B,WAAW,CAAC,KAAK,EAAE,iBAAiB;IAmBpC,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;CAmC3C"}
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ExportUJsonPlugin = exports.exportUJsonLoader = exports.exportUJson = void 0;
27
27
  const export_table_lib_1 = require("export-table-lib");
28
28
  const fs = __importStar(require("fs-extra"));
29
+ const ExportCSPlugin_1 = require("./ExportCSPlugin");
29
30
  var isSkipIndexLoader0 = process.argv.findIndex(v => v == "--SkipIndexLoader") >= 0;
30
31
  let firstLetterUpper = export_table_lib_1.makeFirstLetterUpper;
31
32
  function exportUJson(paras) {
@@ -39,10 +40,44 @@ function exportUJson(paras) {
39
40
  var fullName = `${table.workbookName}-${name}`;
40
41
  let jsonString = JSON.stringify(objects.map(obj => {
41
42
  var newObj = Object.create(null);
42
- Object.keys(obj).forEach(key => {
43
+ for (let f of fields) {
44
+ let key = f.name;
43
45
  var newKey = convMemberName(key);
44
46
  newObj[newKey] = obj[key];
45
- });
47
+ let m = f.rawType.match(/\@\((\w+),(\w+)\)\[\]/);
48
+ if (m != null) {
49
+ // [{"Item1":99,"Item2":"klwjefl"}]
50
+ let content = obj[key];
51
+ let index = 0;
52
+ let index2 = -1;
53
+ let objs = [];
54
+ while (0 <= index && index < content.length) {
55
+ index2 = content.indexOf("|", index);
56
+ let numStr = content.substring(index, index2);
57
+ let t1 = m[1];
58
+ index = content.indexOf(";;", index2);
59
+ let posEnd = index;
60
+ if (index == -1) {
61
+ posEnd = content.length;
62
+ }
63
+ else {
64
+ index += 2;
65
+ }
66
+ let ssStr = content.substring(index2 + 1, posEnd);
67
+ let t2 = m[2];
68
+ console.log(`parseinfo: ${index2}, ${index}, ${numStr}, ${ssStr}, ${t1}, ${t2}`);
69
+ objs.push({
70
+ Item1: (0, ExportCSPlugin_1.TryConvValue)(numStr, t1, f),
71
+ Item2: (0, ExportCSPlugin_1.TryConvValue)(ssStr, t2, f),
72
+ });
73
+ }
74
+ newObj[newKey + "Obj"] = objs;
75
+ }
76
+ }
77
+ // Object.keys(obj).forEach(key => {
78
+ // var newKey = convMemberName(key);
79
+ // newObj[newKey] = obj[key];
80
+ // })
46
81
  return newObj;
47
82
  }));
48
83
  return jsonString;
@@ -146,11 +181,8 @@ namespace ${exportNamespace}
146
181
  }
147
182
  exports.exportUJsonLoader = exportUJsonLoader;
148
183
  class ExportUJsonPlugin extends export_table_lib_1.PluginBase {
149
- constructor() {
150
- super(...arguments);
151
- this.name = "ujson";
152
- this.tags = ["ujson"];
153
- }
184
+ name = "ujson";
185
+ tags = ["ujson"];
154
186
  handleSheet(paras) {
155
187
  var fullName = `${paras.table.workbookName}-${paras.name}`;
156
188
  {
@@ -170,9 +202,8 @@ class ExportUJsonPlugin extends export_table_lib_1.PluginBase {
170
202
  }
171
203
  }
172
204
  handleBatch(paras) {
173
- var _a;
174
205
  let { moreOptions, tables, exportNamespace, } = paras;
175
- let isSkipIndexLoader = (_a = !!moreOptions.SkipIndexLoader) !== null && _a !== void 0 ? _a : false;
206
+ let isSkipIndexLoader = !!moreOptions?.SkipIndexLoader ?? false;
176
207
  if (isSkipIndexLoader0) {
177
208
  isSkipIndexLoader = true;
178
209
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "export-table-pulgin-csharp",
3
- "version": "1.1.84",
3
+ "version": "1.1.86",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
15
  "@types/node": "^17.0.18",
16
- "export-table-lib": "^1.0.55",
16
+ "export-table-lib": "^1.0.56",
17
17
  "fs": "^0.0.1-security",
18
18
  "fs-extra": "^10.0.0",
19
19
  "fse": "^4.0.1"
@@ -1,7 +1,114 @@
1
1
 
2
- import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, iff } from "export-table-lib"
2
+ import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, iff, FieldType } from "export-table-lib"
3
3
  import * as fs from "fs-extra"
4
4
 
5
+ export function TryConvValue(value: any, t: FieldType, f: Field): any {
6
+ try {
7
+ return ConvValue(value, t, f)
8
+ } catch (ex) {
9
+ return null
10
+ }
11
+ }
12
+
13
+ export function ConvValue(value: any, t: FieldType, f: Field): any {
14
+ if (t == "object") {
15
+ return JSON.parse(value)
16
+ } else if (t == "object[]") {
17
+ return JSON.parse(value)
18
+ } else if (t == "number" || t == "int" || t == "long") {
19
+ return JSON.parse(value)
20
+ } else if (t == "number[]") {
21
+ return JSON.parse(value)
22
+ } else if (t == "int[]") {
23
+ return JSON.parse(value)
24
+ } else if (t == "long[]") {
25
+ return JSON.parse(value)
26
+ } else if (t == "uid") {
27
+ return JSON.parse(value)
28
+ } else if (t == "bool") {
29
+ try {
30
+ return !!JSON.parse(value)
31
+ } catch (ex) {
32
+ console.log(ex)
33
+ return false
34
+ }
35
+ } else if (t == "bool[]") {
36
+ return JSON.parse(value)
37
+ } else if (t == "string") {
38
+ return value
39
+ } else if (t == "string[]") {
40
+ return JSON.parse(value)
41
+ } else if (t == "fk") {
42
+ return value
43
+ } else if (t == "fk[]") {
44
+ return value
45
+ } else if (t == "any") {
46
+ console.log(f)
47
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
48
+ } else if (t == "key") {
49
+ return JSON.parse(t)
50
+ }
51
+
52
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
53
+ }
54
+
55
+ export function ConvValue2Literal(value: any, t: FieldType, f: Field): string {
56
+ if (t == "object") {
57
+ //throw new Error("invalid type <object>")
58
+ let convert: string[] = [];
59
+ for (let k in value) {
60
+ convert.push(`{"${k}","${(value as any)[k].toString()}"}`);
61
+ };
62
+ return `new Dictionary<string,string>(${convert.length}){${convert}}`;
63
+ } else if (t == "object[]") {
64
+ let values = value as object[];
65
+ //throw new Error("invalid type <object[]>")
66
+ return `new List<Dictionary<string,string>>(){${values.map((val) => {
67
+ let convert: string[] = [];
68
+ for (let k in val) {
69
+ convert.push(`{"${k}","${(val as any)[k].toString()}"}`);
70
+ };
71
+ return `new Dictionary<string,string>(${convert.length}){${convert}}`;
72
+ })}}`
73
+ } else if (t == "number" || t == "int" || t == "long") {
74
+ return `${value}`
75
+ } else if (t == "number[]") {
76
+ let values = value as number[]
77
+ return `new double[]{${values.join(", ")}}`
78
+ } else if (t == "int[]") {
79
+ let values = value as number[]
80
+ return `new int[]{${values.join(", ")}}`
81
+ } else if (t == "long[]") {
82
+ let values = value as number[]
83
+ return `new long[]{${values.join(", ")}}`
84
+ } else if (t == "uid") {
85
+ return `${value}`
86
+ } else if (t == "bool") {
87
+ return `${value}`
88
+ } else if (t == "bool[]") {
89
+ let values = value as boolean[]
90
+ return `new bool[]{${values.join(", ")}}`
91
+ } else if (t == "string") {
92
+ // return `"${value}"`
93
+ return JSON.stringify(value)
94
+ } else if (t == "string[]") {
95
+ let values = value as string[]
96
+ return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`
97
+ } else if (t == "fk") {
98
+ return `${value}`
99
+ } else if (t == "fk[]") {
100
+ let values = value as number[]
101
+ return `new int[]{${values.join(", ")}}`
102
+ } else if (t == "any") {
103
+ console.log(f)
104
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
105
+ } else if (t == "key") {
106
+ return `${value}`
107
+ }
108
+
109
+ throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
110
+ }
111
+
5
112
  var isSkipExportDefaults0 = process.argv.findIndex(v => v == "--SkipDefaults") >= 0
6
113
 
7
114
  export function export_stuff(paras: HandleSheetParams): string | null {
@@ -18,7 +125,7 @@ export function export_stuff(paras: HandleSheetParams): string | null {
18
125
  moreOptions,
19
126
  } = paras;
20
127
 
21
- let isSkipExportDefaults = !!moreOptions.SkipDefaults ?? false
128
+ let isSkipExportDefaults = !!moreOptions?.SkipDefaults ?? false
22
129
  if (isSkipExportDefaults0) {
23
130
  isSkipExportDefaults = true
24
131
  }
@@ -89,61 +196,7 @@ export function export_stuff(paras: HandleSheetParams): string | null {
89
196
  }
90
197
 
91
198
  const genValue = (value: any, f: Field): string => {
92
- let t = f.type
93
- if (t == "object") {
94
- //throw new Error("invalid type <object>")
95
- let convert: string[] = [];
96
- for (let k in value) {
97
- convert.push(`{"${k}","${(value as any)[k].toString()}"}`);
98
- };
99
- return `new Dictionary<string,string>(${convert.length}){${convert}}`;
100
- } else if (t == "object[]") {
101
- let values = value as object[];
102
- //throw new Error("invalid type <object[]>")
103
- return `new List<Dictionary<string,string>>(){${values.map((val) => {
104
- let convert: string[] = [];
105
- for (let k in val) {
106
- convert.push(`{"${k}","${(val as any)[k].toString()}"}`);
107
- };
108
- return `new Dictionary<string,string>(${convert.length}){${convert}}`;
109
- })}}`
110
- } else if (t == "number" || t == "int" || t == "long") {
111
- return `${value}`
112
- } else if (t == "number[]") {
113
- let values = value as number[]
114
- return `new double[]{${values.join(", ")}}`
115
- } else if (t == "int[]") {
116
- let values = value as number[]
117
- return `new int[]{${values.join(", ")}}`
118
- } else if (t == "long[]") {
119
- let values = value as number[]
120
- return `new long[]{${values.join(", ")}}`
121
- } else if (t == "uid") {
122
- return `${value}`
123
- } else if (t == "bool") {
124
- return `${value}`
125
- } else if (t == "bool[]") {
126
- let values = value as boolean[]
127
- return `new bool[]{${values.join(", ")}}`
128
- } else if (t == "string") {
129
- // return `"${value}"`
130
- return JSON.stringify(value)
131
- } else if (t == "string[]") {
132
- let values = value as string[]
133
- return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`
134
- } else if (t == "fk") {
135
- return `${value}`
136
- } else if (t == "fk[]") {
137
- let values = value as number[]
138
- return `new int[]{${values.join(", ")}}`
139
- } else if (t == "any") {
140
- console.log(f)
141
- throw new Error(`invalid type ${f.name}:<${f.rawType} => any>`)
142
- } else if (t == "key") {
143
- return `${value}`
144
- }
145
-
146
- throw new Error(`invalid type ${f.name}:<${f.rawType} => unkown>`)
199
+ return ConvValue2Literal(value, f.type, f)
147
200
  }
148
201
 
149
202
  const getTitle = (v: Field) => {
@@ -201,8 +254,16 @@ ${foreach(getDescripts(f), line =>
201
254
  ` /// ${line}`
202
255
  )}
203
256
  /// </summary>
204
- public ${getFieldType(f)} ${convMemberName(f.name)};`
205
- )}
257
+ public ${getFieldType(f)} ${convMemberName(f.name)};
258
+
259
+ ${iff(f.rawType.startsWith("@"), () => `
260
+ /// <summary>
261
+ ${foreach(getDescripts(f), line =>
262
+ ` /// ${line}`
263
+ )}
264
+ /// </summary>
265
+ public ${f.rawType.replaceAll(/(?<=[^\w])(number)(?=[^\w]|$)/g, "double").replaceAll(/(?<=[^\w])(boolean)(?=[^\w]|$)/g, "bool")} ${convMemberName(f.name)}Obj;`)}`
266
+ )}
206
267
 
207
268
  ${cmm(/**生成get字段 */)}
208
269
  #region get字段
@@ -1,6 +1,7 @@
1
1
 
2
2
  import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, OutFilePath, makeFirstLetterUpper } from "export-table-lib"
3
3
  import * as fs from "fs-extra"
4
+ import { TryConvValue } from "./ExportCSPlugin";
4
5
 
5
6
  var isSkipIndexLoader0 = process.argv.findIndex(v => v == "--SkipIndexLoader") >= 0
6
7
 
@@ -24,10 +25,44 @@ export function exportUJson(paras: HandleSheetParams): string | null {
24
25
  var fullName = `${table.workbookName}-${name}`
25
26
  let jsonString = JSON.stringify(objects.map(obj => {
26
27
  var newObj = Object.create(null);
27
- Object.keys(obj).forEach(key => {
28
+ for (let f of fields) {
29
+ let key = f.name
28
30
  var newKey = convMemberName(key);
29
31
  newObj[newKey] = obj[key];
30
- })
32
+
33
+ let m = f.rawType.match(/\@\((\w+),(\w+)\)\[\]/)
34
+ if (m != null) {
35
+ // [{"Item1":99,"Item2":"klwjefl"}]
36
+ let content = obj[key] as string;
37
+ let index = 0;
38
+ let index2 = -1;
39
+ let objs: object[] = []
40
+ while (0 <= index && index < content.length) {
41
+ index2 = content.indexOf("|", index)
42
+ let numStr = content.substring(index, index2)
43
+ let t1 = m[1]
44
+ index = content.indexOf(";;", index2)
45
+ let posEnd = index
46
+ if (index == -1) {
47
+ posEnd = content.length
48
+ } else {
49
+ index += 2
50
+ }
51
+ let ssStr = content.substring(index2 + 1, posEnd)
52
+ let t2 = m[2]
53
+ console.log(`parseinfo: ${index2}, ${index}, ${numStr}, ${ssStr}, ${t1}, ${t2}`)
54
+ objs.push({
55
+ Item1: TryConvValue(numStr, t1 as any, f),
56
+ Item2: TryConvValue(ssStr, t2 as any, f),
57
+ })
58
+ }
59
+ newObj[newKey + "Obj"] = objs
60
+ }
61
+ }
62
+ // Object.keys(obj).forEach(key => {
63
+ // var newKey = convMemberName(key);
64
+ // newObj[newKey] = obj[key];
65
+ // })
31
66
  return newObj
32
67
  }));
33
68
 
@@ -173,7 +208,7 @@ export class ExportUJsonPlugin extends PluginBase {
173
208
  tables,
174
209
  exportNamespace,
175
210
  } = paras
176
- let isSkipIndexLoader = !!moreOptions.SkipIndexLoader ?? false
211
+ let isSkipIndexLoader = !!moreOptions?.SkipIndexLoader ?? false
177
212
  if (isSkipIndexLoader0) {
178
213
  isSkipIndexLoader = true
179
214
  }
package/tsconfig.json CHANGED
@@ -11,7 +11,7 @@
11
11
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
12
 
13
13
  /* Language and Environment */
14
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14
+ "target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
15
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
17
17
  // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */