diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2020-04-11 16:09:34 +1000 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2020-04-13 20:25:55 +1000 |
commit | f5b9effe3945b7faf8a5b4876eb57dc52e7c7f96 (patch) | |
tree | 85ecd373ef01f7fa08809633064b0847c70b3d7b /src | |
parent | 6a08e97de12e6f091d0ff77dcad5d1660c807e19 (diff) | |
download | wix-f5b9effe3945b7faf8a5b4876eb57dc52e7c7f96.tar.gz wix-f5b9effe3945b7faf8a5b4876eb57dc52e7c7f96.tar.bz2 wix-f5b9effe3945b7faf8a5b4876eb57dc52e7c7f96.zip |
Update TablesAndTuples for Core
Diffstat (limited to 'src')
-rw-r--r-- | src/TablesAndTuples/Program.cs | 56 | ||||
-rw-r--r-- | src/TablesAndTuples/WixTableDefinition.cs | 13 |
2 files changed, 50 insertions, 19 deletions
diff --git a/src/TablesAndTuples/Program.cs b/src/TablesAndTuples/Program.cs index 400d58fa..99b15a8c 100644 --- a/src/TablesAndTuples/Program.cs +++ b/src/TablesAndTuples/Program.cs | |||
@@ -65,6 +65,10 @@ namespace TablesAndTuples | |||
65 | 65 | ||
66 | foreach (var tableDefinition in tableDefinitions) | 66 | foreach (var tableDefinition in tableDefinitions) |
67 | { | 67 | { |
68 | if (tableDefinition.Tupleless) | ||
69 | { | ||
70 | continue; | ||
71 | } | ||
68 | var tupleType = tableDefinition.TupleDefinitionName; | 72 | var tupleType = tableDefinition.TupleDefinitionName; |
69 | 73 | ||
70 | var fields = new JsonArray(); | 74 | var fields = new JsonArray(); |
@@ -199,9 +203,10 @@ namespace TablesAndTuples | |||
199 | " },"); | 203 | " },"); |
200 | var unrealDef = | 204 | var unrealDef = |
201 | " unreal: true,"; | 205 | " unreal: true,"; |
206 | var tupleNameDef = | ||
207 | " tupleDefinitionName: {1}TupleDefinitions.{2}.Name,"; | ||
202 | var endTableDef = String.Join(Environment.NewLine, | 208 | var endTableDef = String.Join(Environment.NewLine, |
203 | " tupleDefinitionName: {1}TupleDefinitions.{2}.Name,", | 209 | " tupleIdIsPrimaryKey: {1}", |
204 | " tupleIdIsPrimaryKey: {3}", | ||
205 | " );", | 210 | " );", |
206 | ""); | 211 | ""); |
207 | var startAllTablesDef = String.Join(Environment.NewLine, | 212 | var startAllTablesDef = String.Join(Environment.NewLine, |
@@ -247,7 +252,7 @@ namespace TablesAndTuples | |||
247 | } | 252 | } |
248 | if (!String.IsNullOrEmpty(columnDefinition.Description)) | 253 | if (!String.IsNullOrEmpty(columnDefinition.Description)) |
249 | { | 254 | { |
250 | sb.AppendFormat(", description: \"{0}\"", columnDefinition.Description); | 255 | sb.AppendFormat(", description: \"{0}\"", columnDefinition.Description.Replace("\\", "\\\\").Replace("\"", "\\\"")); |
251 | } | 256 | } |
252 | if (columnDefinition.ModularizeType.HasValue && columnDefinition.ModularizeType.Value != ColumnModularizeType.None) | 257 | if (columnDefinition.ModularizeType.HasValue && columnDefinition.ModularizeType.Value != ColumnModularizeType.None) |
253 | { | 258 | { |
@@ -272,7 +277,11 @@ namespace TablesAndTuples | |||
272 | { | 277 | { |
273 | sb.AppendLine(unrealDef); | 278 | sb.AppendLine(unrealDef); |
274 | } | 279 | } |
275 | sb.AppendLine(endTableDef.Replace("{1}", prefix).Replace("{2}", tableDefinition.TupleDefinitionName).Replace("{3}", tableDefinition.TupleIdIsPrimaryKey.ToString().ToLower())); | 280 | if (!tableDefinition.Tupleless) |
281 | { | ||
282 | sb.AppendLine(tupleNameDef.Replace("{1}", prefix).Replace("{2}", tableDefinition.TupleDefinitionName)); | ||
283 | } | ||
284 | sb.AppendLine(endTableDef.Replace("{1}", tableDefinition.TupleIdIsPrimaryKey.ToString().ToLower())); | ||
276 | } | 285 | } |
277 | sb.AppendLine(startAllTablesDef); | 286 | sb.AppendLine(startAllTablesDef); |
278 | foreach (var tableDefinition in tableDefinitions) | 287 | foreach (var tableDefinition in tableDefinitions) |
@@ -290,19 +299,21 @@ namespace TablesAndTuples | |||
290 | var ns = prefix ?? "Data"; | 299 | var ns = prefix ?? "Data"; |
291 | var toString = String.IsNullOrEmpty(prefix) ? null : ".ToString()"; | 300 | var toString = String.IsNullOrEmpty(prefix) ? null : ".ToString()"; |
292 | 301 | ||
293 | var startTupleDef = String.Join(Environment.NewLine, | 302 | var startFileDef = String.Join(Environment.NewLine, |
294 | "// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.", | 303 | "// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.", |
295 | "", | 304 | "", |
296 | "namespace WixToolset.{2}", | 305 | "namespace WixToolset.{2}", |
297 | "{", | 306 | "{"); |
298 | " using WixToolset.Data;", | 307 | var usingDataDef = |
308 | " using WixToolset.Data;"; | ||
309 | var startTupleDef = String.Join(Environment.NewLine, | ||
299 | " using WixToolset.{2}.Tuples;", | 310 | " using WixToolset.{2}.Tuples;", |
300 | "", | 311 | "", |
301 | " public static partial class {3}TupleDefinitions", | 312 | " public static partial class {3}TupleDefinitions", |
302 | " {", | 313 | " {", |
303 | " public static readonly IntermediateTupleDefinition {1} = new IntermediateTupleDefinition(", | 314 | " public static readonly IntermediateTupleDefinition {1} = new IntermediateTupleDefinition(", |
304 | " {3}TupleDefinitionType.{1}{4},", | 315 | " {3}TupleDefinitionType.{1}{4},", |
305 | " new[]", | 316 | " new{5}[]", |
306 | " {"); | 317 | " {"); |
307 | var fieldDef = | 318 | var fieldDef = |
308 | " new IntermediateFieldDefinition(nameof({1}TupleFields.{2}), IntermediateFieldType.{3}),"; | 319 | " new IntermediateFieldDefinition(nameof({1}TupleFields.{2}), IntermediateFieldType.{3}),"; |
@@ -313,9 +324,8 @@ namespace TablesAndTuples | |||
313 | "}", | 324 | "}", |
314 | "", | 325 | "", |
315 | "namespace WixToolset.{2}.Tuples", | 326 | "namespace WixToolset.{2}.Tuples", |
316 | "{", | 327 | "{"); |
317 | " using WixToolset.Data;", | 328 | var startEnumDef = String.Join(Environment.NewLine, |
318 | "", | ||
319 | " public enum {1}TupleFields", | 329 | " public enum {1}TupleFields", |
320 | " {"); | 330 | " {"); |
321 | var fieldEnum = | 331 | var fieldEnum = |
@@ -338,7 +348,7 @@ namespace TablesAndTuples | |||
338 | "", | 348 | "", |
339 | " public {4} {2}", | 349 | " public {4} {2}", |
340 | " {", | 350 | " {", |
341 | " get => this.Fields[(int){1}TupleFields.{2}].{5};", | 351 | " get => {6}this.Fields[(int){1}TupleFields.{2}]{5};", |
342 | " set => this.Set((int){1}TupleFields.{2}, value);", | 352 | " set => this.Set((int){1}TupleFields.{2}, value);", |
343 | " }"); | 353 | " }"); |
344 | var endTuple = String.Join(Environment.NewLine, | 354 | var endTuple = String.Join(Environment.NewLine, |
@@ -347,20 +357,34 @@ namespace TablesAndTuples | |||
347 | 357 | ||
348 | var sb = new StringBuilder(); | 358 | var sb = new StringBuilder(); |
349 | 359 | ||
350 | sb.AppendLine(startTupleDef.Replace("{1}", tupleName).Replace("{2}", ns).Replace("{3}", prefix).Replace("{4}", toString)); | 360 | sb.AppendLine(startFileDef.Replace("{2}", ns)); |
361 | if (ns != "Data") | ||
362 | { | ||
363 | sb.AppendLine(usingDataDef); | ||
364 | } | ||
365 | sb.AppendLine(startTupleDef.Replace("{1}", tupleName).Replace("{2}", ns).Replace("{3}", prefix).Replace("{4}", toString).Replace("{5}", tupleFields.Any() ? null : " IntermediateFieldDefinition")); | ||
351 | foreach (var field in tupleFields) | 366 | foreach (var field in tupleFields) |
352 | { | 367 | { |
353 | sb.AppendLine(fieldDef.Replace("{1}", tupleName).Replace("{2}", field.Name).Replace("{3}", field.Type).Replace("{4}", field.ClrType).Replace("{5}", field.AsFunction)); | 368 | sb.AppendLine(fieldDef.Replace("{1}", tupleName).Replace("{2}", field.Name).Replace("{3}", field.Type)); |
354 | } | 369 | } |
355 | sb.AppendLine(endTupleDef.Replace("{1}", tupleName).Replace("{2}", ns).Replace("{3}", prefix)); | 370 | sb.AppendLine(endTupleDef.Replace("{1}", tupleName).Replace("{2}", ns).Replace("{3}", prefix)); |
371 | if (ns != "Data") | ||
372 | { | ||
373 | sb.AppendLine(usingDataDef); | ||
374 | sb.AppendLine(); | ||
375 | } | ||
376 | sb.AppendLine(startEnumDef.Replace("{1}", tupleName)); | ||
356 | foreach (var field in tupleFields) | 377 | foreach (var field in tupleFields) |
357 | { | 378 | { |
358 | sb.AppendLine(fieldEnum.Replace("{1}", tupleName).Replace("{2}", field.Name).Replace("{3}", field.Type).Replace("{4}", field.ClrType).Replace("{5}", field.AsFunction)); | 379 | sb.AppendLine(fieldEnum.Replace("{1}", tupleName).Replace("{2}", field.Name)); |
359 | } | 380 | } |
360 | sb.AppendLine(startTuple.Replace("{1}", tupleName).Replace("{2}", ns).Replace("{3}", prefix)); | 381 | sb.AppendLine(startTuple.Replace("{1}", tupleName).Replace("{2}", ns).Replace("{3}", prefix)); |
361 | foreach (var field in tupleFields) | 382 | foreach (var field in tupleFields) |
362 | { | 383 | { |
363 | sb.AppendLine(fieldProp.Replace("{1}", tupleName).Replace("{2}", field.Name).Replace("{3}", field.Type).Replace("{4}", field.ClrType).Replace("{5}", field.AsFunction)); | 384 | var useCast = ns == "Data" && field.AsFunction != "AsPath()"; |
385 | var cast = useCast ? $"({field.ClrType})" : null; | ||
386 | var asFunction = useCast ? null : $".{field.AsFunction}"; | ||
387 | sb.AppendLine(fieldProp.Replace("{1}", tupleName).Replace("{2}", field.Name).Replace("{3}", field.Type).Replace("{4}", field.ClrType).Replace("{5}", asFunction).Replace("{6}", cast)); | ||
364 | } | 388 | } |
365 | sb.Append(endTuple); | 389 | sb.Append(endTuple); |
366 | 390 | ||
diff --git a/src/TablesAndTuples/WixTableDefinition.cs b/src/TablesAndTuples/WixTableDefinition.cs index baada41d..fde107ad 100644 --- a/src/TablesAndTuples/WixTableDefinition.cs +++ b/src/TablesAndTuples/WixTableDefinition.cs | |||
@@ -6,12 +6,13 @@ namespace TablesAndTuples | |||
6 | { | 6 | { |
7 | class WixTableDefinition | 7 | class WixTableDefinition |
8 | { | 8 | { |
9 | public WixTableDefinition(string name, IEnumerable<WixColumnDefinition> columns, bool unreal, string tupleDefinitionName, bool? tupleIdIsPrimaryKey) | 9 | public WixTableDefinition(string name, IEnumerable<WixColumnDefinition> columns, bool unreal, bool tupleless, string tupleDefinitionName, bool? tupleIdIsPrimaryKey) |
10 | { | 10 | { |
11 | this.Name = name; | 11 | this.Name = name; |
12 | this.Unreal = unreal; | 12 | this.Unreal = unreal; |
13 | this.Columns = columns?.ToArray(); | 13 | this.Columns = columns?.ToArray(); |
14 | this.TupleDefinitionName = tupleDefinitionName ?? name; | 14 | this.Tupleless = tupleless; |
15 | this.TupleDefinitionName = tupleless ? null : tupleDefinitionName ?? name.Replace("_", ""); | ||
15 | this.TupleIdIsPrimaryKey = tupleIdIsPrimaryKey ?? DeriveTupleIdIsPrimaryKey(this.Columns); | 16 | this.TupleIdIsPrimaryKey = tupleIdIsPrimaryKey ?? DeriveTupleIdIsPrimaryKey(this.Columns); |
16 | } | 17 | } |
17 | 18 | ||
@@ -25,6 +26,8 @@ namespace TablesAndTuples | |||
25 | 26 | ||
26 | public bool TupleIdIsPrimaryKey { get; } | 27 | public bool TupleIdIsPrimaryKey { get; } |
27 | 28 | ||
29 | public bool Tupleless { get; } | ||
30 | |||
28 | static WixTableDefinition Read(XmlReader reader) | 31 | static WixTableDefinition Read(XmlReader reader) |
29 | { | 32 | { |
30 | var empty = reader.IsEmptyElement; | 33 | var empty = reader.IsEmptyElement; |
@@ -32,6 +35,7 @@ namespace TablesAndTuples | |||
32 | string tupleDefinitionName = null; | 35 | string tupleDefinitionName = null; |
33 | var unreal = false; | 36 | var unreal = false; |
34 | bool? tupleIdIsPrimaryKey = null; | 37 | bool? tupleIdIsPrimaryKey = null; |
38 | var tupleless = false; | ||
35 | 39 | ||
36 | while (reader.MoveToNextAttribute()) | 40 | while (reader.MoveToNextAttribute()) |
37 | { | 41 | { |
@@ -46,6 +50,9 @@ namespace TablesAndTuples | |||
46 | case "tupleIdIsPrimaryKey": | 50 | case "tupleIdIsPrimaryKey": |
47 | tupleIdIsPrimaryKey = reader.Value.Equals("yes"); | 51 | tupleIdIsPrimaryKey = reader.Value.Equals("yes"); |
48 | break; | 52 | break; |
53 | case "tupleless": | ||
54 | tupleless = reader.Value.Equals("yes"); | ||
55 | break; | ||
49 | case "unreal": | 56 | case "unreal": |
50 | unreal = reader.Value.Equals("yes"); | 57 | unreal = reader.Value.Equals("yes"); |
51 | break; | 58 | break; |
@@ -91,7 +98,7 @@ namespace TablesAndTuples | |||
91 | } | 98 | } |
92 | } | 99 | } |
93 | 100 | ||
94 | return new WixTableDefinition(name, columns.ToArray(), unreal, tupleDefinitionName, tupleIdIsPrimaryKey); | 101 | return new WixTableDefinition(name, columns.ToArray(), unreal, tupleless, tupleDefinitionName, tupleIdIsPrimaryKey); |
95 | } | 102 | } |
96 | 103 | ||
97 | static bool DeriveTupleIdIsPrimaryKey(WixColumnDefinition[] columns) | 104 | static bool DeriveTupleIdIsPrimaryKey(WixColumnDefinition[] columns) |