@joebigelow / wix / commits / f5b9effe

Update TablesAndTuples for Core

Sean Hall committed Apr 11, 2020 at 16:09 UTC f5b9effe3945b7faf8a5b4876eb57dc52e7c7f96
2 files changed +50 -19
src/TablesAndTuples/Program.cs
+40 -16
@@ -65,6 +65,10 @@ namespace TablesAndTuples
65
66 foreach (var tableDefinition in tableDefinitions)
67 {
68 + if (tableDefinition.Tupleless)
69 + {
70 + continue;
71 + }
72 var tupleType = tableDefinition.TupleDefinitionName;
73
74 var fields = new JsonArray();
@@ -199,9 +203,10 @@ namespace TablesAndTuples
203 " },");
204 var unrealDef =
205 " unreal: true,";
206 + var tupleNameDef =
207 + " tupleDefinitionName: {1}TupleDefinitions.{2}.Name,";
208 var endTableDef = String.Join(Environment.NewLine,
203 - " tupleDefinitionName: {1}TupleDefinitions.{2}.Name,",
204 - " tupleIdIsPrimaryKey: {3}",
209 + " tupleIdIsPrimaryKey: {1}",
210 " );",
211 "");
212 var startAllTablesDef = String.Join(Environment.NewLine,
@@ -247,7 +252,7 @@ namespace TablesAndTuples
252 }
253 if (!String.IsNullOrEmpty(columnDefinition.Description))
254 {
250 - sb.AppendFormat(", description: \"{0}\"", columnDefinition.Description);
255 + sb.AppendFormat(", description: \"{0}\"", columnDefinition.Description.Replace("\\", "\\\\").Replace("\"", "\\\""));
256 }
257 if (columnDefinition.ModularizeType.HasValue && columnDefinition.ModularizeType.Value != ColumnModularizeType.None)
258 {
@@ -272,7 +277,11 @@ namespace TablesAndTuples
277 {
278 sb.AppendLine(unrealDef);
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()));
285 }
286 sb.AppendLine(startAllTablesDef);
287 foreach (var tableDefinition in tableDefinitions)
@@ -290,19 +299,21 @@ namespace TablesAndTuples
299 var ns = prefix ?? "Data";
300 var toString = String.IsNullOrEmpty(prefix) ? null : ".ToString()";
301
293 - var startTupleDef = String.Join(Environment.NewLine,
302 + var startFileDef = String.Join(Environment.NewLine,
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.",
304 "",
305 "namespace WixToolset.{2}",
297 - "{",
298 - " using WixToolset.Data;",
306 + "{");
307 + var usingDataDef =
308 + " using WixToolset.Data;";
309 + var startTupleDef = String.Join(Environment.NewLine,
310 " using WixToolset.{2}.Tuples;",
311 "",
312 " public static partial class {3}TupleDefinitions",
313 " {",
314 " public static readonly IntermediateTupleDefinition {1} = new IntermediateTupleDefinition(",
315 " {3}TupleDefinitionType.{1}{4},",
305 - " new[]",
316 + " new{5}[]",
317 " {");
318 var fieldDef =
319 " new IntermediateFieldDefinition(nameof({1}TupleFields.{2}), IntermediateFieldType.{3}),";
@@ -313,9 +324,8 @@ namespace TablesAndTuples
324 "}",
325 "",
326 "namespace WixToolset.{2}.Tuples",
316 - "{",
317 - " using WixToolset.Data;",
318 - "",
327 + "{");
328 + var startEnumDef = String.Join(Environment.NewLine,
329 " public enum {1}TupleFields",
330 " {");
331 var fieldEnum =
@@ -338,7 +348,7 @@ namespace TablesAndTuples
348 "",
349 " public {4} {2}",
350 " {",
341 - " get => this.Fields[(int){1}TupleFields.{2}].{5};",
351 + " get => {6}this.Fields[(int){1}TupleFields.{2}]{5};",
352 " set => this.Set((int){1}TupleFields.{2}, value);",
353 " }");
354 var endTuple = String.Join(Environment.NewLine,
@@ -347,20 +357,34 @@ namespace TablesAndTuples
357
358 var sb = new StringBuilder();
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"));
366 foreach (var field in tupleFields)
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));
369 }
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));
377 foreach (var field in tupleFields)
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));
380 }
381 sb.AppendLine(startTuple.Replace("{1}", tupleName).Replace("{2}", ns).Replace("{3}", prefix));
382 foreach (var field in tupleFields)
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));
388 }
389 sb.Append(endTuple);
390
src/TablesAndTuples/WixTableDefinition.cs
+10 -3
@@ -6,12 +6,13 @@ namespace TablesAndTuples
6 {
7 class WixTableDefinition
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 {
11 this.Name = name;
12 this.Unreal = unreal;
13 this.Columns = columns?.ToArray();
14 - this.TupleDefinitionName = tupleDefinitionName ?? name;
14 + this.Tupleless = tupleless;
15 + this.TupleDefinitionName = tupleless ? null : tupleDefinitionName ?? name.Replace("_", "");
16 this.TupleIdIsPrimaryKey = tupleIdIsPrimaryKey ?? DeriveTupleIdIsPrimaryKey(this.Columns);
17 }
18
@@ -25,6 +26,8 @@ namespace TablesAndTuples
26
27 public bool TupleIdIsPrimaryKey { get; }
28
29 + public bool Tupleless { get; }
30 +
31 static WixTableDefinition Read(XmlReader reader)
32 {
33 var empty = reader.IsEmptyElement;
@@ -32,6 +35,7 @@ namespace TablesAndTuples
35 string tupleDefinitionName = null;
36 var unreal = false;
37 bool? tupleIdIsPrimaryKey = null;
38 + var tupleless = false;
39
40 while (reader.MoveToNextAttribute())
41 {
@@ -46,6 +50,9 @@ namespace TablesAndTuples
50 case "tupleIdIsPrimaryKey":
51 tupleIdIsPrimaryKey = reader.Value.Equals("yes");
52 break;
53 + case "tupleless":
54 + tupleless = reader.Value.Equals("yes");
55 + break;
56 case "unreal":
57 unreal = reader.Value.Equals("yes");
58 break;
@@ -91,7 +98,7 @@ namespace TablesAndTuples
98 }
99 }
100
94 - return new WixTableDefinition(name, columns.ToArray(), unreal, tupleDefinitionName, tupleIdIsPrimaryKey);
101 + return new WixTableDefinition(name, columns.ToArray(), unreal, tupleless, tupleDefinitionName, tupleIdIsPrimaryKey);
102 }
103
104 static bool DeriveTupleIdIsPrimaryKey(WixColumnDefinition[] columns)