Test ability for an extension to have a custom strongly typed row during binding.
Sean Hall committed
Apr 18, 2020 at 14:43 UTC
a6091afa5bd24fe65e7fc20f179ed888301afdf8
7 files changed
+85
-33
src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs
+1
-1
@@ -307,7 +307,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
307
308
// process modified and unmodified rows
309
var modifiedRow = false;
310
- var targetRow = new Row(null, table.Definition);
310
+ var targetRow = table.Definition.CreateRow(null);
311
var updatedRow = row;
312
for (var i = 0; i < row.Fields.Length; i++)
313
{
src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs
+1
-1
@@ -747,7 +747,7 @@ namespace WixToolset.Core.WindowsInstaller
747
property.Id = id;
748
749
// create a dummy row for indexing
750
- var row = new Row(null, this.tableDefinitions["Property"]);
750
+ var row = this.tableDefinitions["Property"].CreateRow(null);
751
row[0] = id;
752
753
this.core.RootElement.AddChild(property);
src/test/Example.Extension/ExampleExtensionData.cs
+1
-15
@@ -16,21 +16,7 @@ namespace Example.Extension
16
17
public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition)
18
{
19
- switch (name)
20
- {
21
- case "Example":
22
- tupleDefinition = ExampleTupleDefinitions.Example;
23
- break;
24
-
25
- case "ExampleSearch":
26
- tupleDefinition = ExampleTupleDefinitions.ExampleSearch;
27
- break;
28
-
29
- default:
30
- tupleDefinition = null;
31
- break;
32
- }
33
-
19
+ tupleDefinition = ExampleTupleDefinitions.ByName(name);
20
return tupleDefinition != null;
21
}
22
}
src/test/Example.Extension/ExampleRow.cs
new
+32
@@ -0,0 +1,32 @@
1
+// 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.
2
+
3
+namespace Example.Extension
4
+{
5
+ using WixToolset.Data;
6
+ using WixToolset.Data.WindowsInstaller;
7
+
8
+ public class ExampleRow : Row
9
+ {
10
+ public ExampleRow(SourceLineNumber sourceLineNumbers, Table table)
11
+ : base(sourceLineNumbers, table)
12
+ {
13
+ }
14
+
15
+ public ExampleRow(SourceLineNumber sourceLineNumbers, TableDefinition tableDefinition)
16
+ : base(sourceLineNumbers, tableDefinition)
17
+ {
18
+ }
19
+
20
+ public string Example
21
+ {
22
+ get { return (string)this.Fields[0].Data; }
23
+ set { this.Fields[0].Data = value; }
24
+ }
25
+
26
+ public string Value
27
+ {
28
+ get { return (string)this.Fields[1].Data; }
29
+ set { this.Fields[1].Data = value; }
30
+ }
31
+ }
32
+}
src/test/Example.Extension/ExampleTableDefinitions.cs
+1
@@ -14,6 +14,7 @@ namespace Example.Extension
14
new ColumnDefinition("Example", ColumnType.String, 72, true, false, ColumnCategory.Identifier),
15
new ColumnDefinition("Value", ColumnType.String, 0, false, false, ColumnCategory.Formatted),
16
},
17
+ strongRowType: typeof(ExampleRow),
18
tupleIdIsPrimaryKey: true
19
);
20
src/test/Example.Extension/ExampleTupleDefinitions.cs
+38
-4
@@ -2,15 +2,20 @@
2
3
namespace Example.Extension
4
{
5
+ using System;
6
using WixToolset.Data;
7
using WixToolset.Data.Burn;
8
8
- public static class ExampleTupleDefinitions
9
+ public enum ExampleTupleDefinitionType
10
{
10
- public const string ExampleName = "Example";
11
+ Example,
12
+ ExampleSearch,
13
+ }
14
15
+ public static class ExampleTupleDefinitions
16
+ {
17
public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition(
13
- ExampleName,
18
+ ExampleTupleDefinitionType.Example.ToString(),
19
new[]
20
{
21
new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String),
@@ -18,7 +23,7 @@ namespace Example.Extension
23
typeof(ExampleTuple));
24
25
public static readonly IntermediateTupleDefinition ExampleSearch = new IntermediateTupleDefinition(
21
- nameof(ExampleSearch),
26
+ ExampleTupleDefinitionType.ExampleSearch.ToString(),
27
new[]
28
{
29
new IntermediateFieldDefinition(nameof(ExampleSearchTupleFields.SearchFor), IntermediateFieldType.String),
@@ -29,5 +34,34 @@ namespace Example.Extension
34
{
35
ExampleSearch.AddTag(BurnConstants.BundleExtensionSearchTupleDefinitionTag);
36
}
37
+
38
+ public static bool TryGetTupleType(string name, out ExampleTupleDefinitionType type)
39
+ {
40
+ return Enum.TryParse(name, out type);
41
+ }
42
+
43
+ public static IntermediateTupleDefinition ByName(string name)
44
+ {
45
+ if (!TryGetTupleType(name, out var type))
46
+ {
47
+ return null;
48
+ }
49
+ return ByType(type);
50
+ }
51
+
52
+ public static IntermediateTupleDefinition ByType(ExampleTupleDefinitionType type)
53
+ {
54
+ switch (type)
55
+ {
56
+ case ExampleTupleDefinitionType.Example:
57
+ return ExampleTupleDefinitions.Example;
58
+
59
+ case ExampleTupleDefinitionType.ExampleSearch:
60
+ return ExampleTupleDefinitions.ExampleSearch;
61
+
62
+ default:
63
+ throw new ArgumentOutOfRangeException(nameof(type));
64
+ }
65
+ }
66
}
67
}
src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs
+11
-12
@@ -13,22 +13,21 @@ namespace Example.Extension
13
14
public override bool TryAddTupleToOutput(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinitionCollection tableDefinitions)
15
{
16
-#if ALTERNATIVE_TO_USING_HELPER
17
- switch (tuple.Definition.Name)
16
+ if (ExampleTupleDefinitions.TryGetTupleType(tuple.Definition.Name, out var tupleType))
17
{
19
- case ExampleTupleDefinitions.ExampleName:
20
- {
21
- var row = this.BackendHelper.CreateRow(section, tuple, output, ExampleTableDefinitions.ExampleTable);
22
- row[0] = tuple[0].AsString();
23
- row[1] = tuple[1].AsString();
24
- }
25
- return true;
18
+ switch (tupleType)
19
+ {
20
+ case ExampleTupleDefinitionType.Example:
21
+ {
22
+ var row = (ExampleRow)this.BackendHelper.CreateRow(section, tuple, output, ExampleTableDefinitions.ExampleTable);
23
+ row.Example = tuple.Id.Id;
24
+ row.Value = tuple[0].AsString();
25
+ }
26
+ return true;
27
+ }
28
}
29
28
- return false;
29
-#else
30
return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(section, tuple, output, tableDefinitions);
31
-#endif
31
}
32
}
33
}