aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2019-05-24 08:47:36 -0700
committerRob Mensching <rob@firegiant.com>2019-05-24 15:18:30 -0700
commit7462108b714d07161126dcedda5312daef54ae13 (patch)
tree5d7021acbbedafd6373fc26c609c2d4c85332075
parent9d0fea2e7617e4ba4fc85fbe412c812d9bc65564 (diff)
downloadwix-7462108b714d07161126dcedda5312daef54ae13.tar.gz
wix-7462108b714d07161126dcedda5312daef54ae13.tar.bz2
wix-7462108b714d07161126dcedda5312daef54ae13.zip
Add tuple.IsNull(), remove fields when set to default and other small fixes
-rw-r--r--src/WixToolset.Data/IntermediateField.cs41
-rw-r--r--src/WixToolset.Data/IntermediateFieldExtensions.cs2
-rw-r--r--src/WixToolset.Data/IntermediateFieldValue.cs30
-rw-r--r--src/WixToolset.Data/IntermediateTuple.cs4
-rw-r--r--src/WixToolset.Data/IntermediateTupleExtensions.cs74
-rw-r--r--src/WixToolset.Data/Tuples/RemoveRegistryTuple.cs2
-rw-r--r--src/WixToolset.Data/Tuples/WixBundleTuple.cs6
7 files changed, 78 insertions, 81 deletions
diff --git a/src/WixToolset.Data/IntermediateField.cs b/src/WixToolset.Data/IntermediateField.cs
index 9aed3d81..5b511d02 100644
--- a/src/WixToolset.Data/IntermediateField.cs
+++ b/src/WixToolset.Data/IntermediateField.cs
@@ -1,4 +1,4 @@
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. 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 2
3namespace WixToolset.Data 3namespace WixToolset.Data
4{ 4{
@@ -9,10 +9,7 @@ namespace WixToolset.Data
9 [DebuggerDisplay("Name={Name,nq} Type={Type} Value={Value?.AsString()}")] 9 [DebuggerDisplay("Name={Name,nq} Type={Type} Value={Value?.AsString()}")]
10 public class IntermediateField 10 public class IntermediateField
11 { 11 {
12 public IntermediateField(IntermediateFieldDefinition definition) 12 public IntermediateField(IntermediateFieldDefinition definition) => this.Definition = definition;
13 {
14 this.Definition = definition;
15 }
16 13
17 public IntermediateFieldDefinition Definition { get; } 14 public IntermediateFieldDefinition Definition { get; }
18 15
@@ -26,46 +23,30 @@ namespace WixToolset.Data
26 23
27 internal IntermediateFieldValue Value { get; set; } 24 internal IntermediateFieldValue Value { get; set; }
28 25
29 public static explicit operator bool(IntermediateField field) 26 public static explicit operator bool(IntermediateField field) => field.AsBool();
30 {
31 return field.AsBool();
32 }
33 27
34 public static explicit operator bool? (IntermediateField field) 28 public static explicit operator bool? (IntermediateField field) => field.AsNullableBool();
35 {
36 return field.AsNullableBool();
37 }
38 29
39 public static explicit operator int(IntermediateField field) 30 public static explicit operator int(IntermediateField field) => field.AsNumber();
40 {
41 return field.AsNumber();
42 }
43 31
44 public static explicit operator int? (IntermediateField field) 32 public static explicit operator int? (IntermediateField field) => field.AsNullableNumber();
45 {
46 return field.AsNullableNumber();
47 }
48 33
49 public static explicit operator string(IntermediateField field) 34 public static explicit operator string(IntermediateField field) => field.AsString();
50 {
51 return field.AsString();
52 }
53 35
54 internal static IntermediateField Deserialize(IntermediateFieldDefinition definition, Uri baseUri, JsonObject jsonObject) 36 internal static IntermediateField Deserialize(IntermediateFieldDefinition definition, Uri baseUri, JsonObject jsonObject)
55 { 37 {
56 var field = new IntermediateField(definition); 38 IntermediateField field = null;
57 39
58 if (jsonObject != null) 40 if (jsonObject != null)
59 { 41 {
42 field = new IntermediateField(definition);
43
60 field.Value = IntermediateFieldValue.Deserialize(jsonObject, baseUri, definition.Type); 44 field.Value = IntermediateFieldValue.Deserialize(jsonObject, baseUri, definition.Type);
61 } 45 }
62 46
63 return field; 47 return field;
64 } 48 }
65 49
66 internal JsonObject Serialize() 50 internal JsonObject Serialize() => this.Value?.Serialize();
67 {
68 return this.Value?.Serialize();
69 }
70 } 51 }
71} 52}
diff --git a/src/WixToolset.Data/IntermediateFieldExtensions.cs b/src/WixToolset.Data/IntermediateFieldExtensions.cs
index 2f8aec1d..a73a6552 100644
--- a/src/WixToolset.Data/IntermediateFieldExtensions.cs
+++ b/src/WixToolset.Data/IntermediateFieldExtensions.cs
@@ -9,6 +9,8 @@ namespace WixToolset.Data
9 [ThreadStatic] 9 [ThreadStatic]
10 internal static string valueContext; 10 internal static string valueContext;
11 11
12 public static bool IsNull(this IntermediateField field) => field?.Value?.Data == null;
13
12 public static bool AsBool(this IntermediateField field) 14 public static bool AsBool(this IntermediateField field)
13 { 15 {
14 if (field == null || field.Value == null || field.Value.Data == null) 16 if (field == null || field.Value == null || field.Value.Data == null)
diff --git a/src/WixToolset.Data/IntermediateFieldValue.cs b/src/WixToolset.Data/IntermediateFieldValue.cs
index b09903dc..ca109e7f 100644
--- a/src/WixToolset.Data/IntermediateFieldValue.cs
+++ b/src/WixToolset.Data/IntermediateFieldValue.cs
@@ -15,35 +15,17 @@ namespace WixToolset.Data
15 15
16 public IntermediateFieldValue PreviousValue { get; internal set; } 16 public IntermediateFieldValue PreviousValue { get; internal set; }
17 17
18 public static explicit operator bool(IntermediateFieldValue value) 18 public static explicit operator bool(IntermediateFieldValue value) => value.AsBool();
19 {
20 return value.AsBool();
21 }
22 19
23 public static explicit operator bool? (IntermediateFieldValue value) 20 public static explicit operator bool? (IntermediateFieldValue value) => value.AsNullableBool();
24 {
25 return value.AsNullableBool();
26 }
27 21
28 public static explicit operator int(IntermediateFieldValue value) 22 public static explicit operator int(IntermediateFieldValue value) => value.AsNumber();
29 {
30 return value.AsNumber();
31 }
32 23
33 public static explicit operator int? (IntermediateFieldValue value) 24 public static explicit operator int? (IntermediateFieldValue value) => value.AsNullableNumber();
34 {
35 return value.AsNullableNumber();
36 }
37 25
38 public static explicit operator IntermediateFieldPathValue(IntermediateFieldValue value) 26 public static explicit operator IntermediateFieldPathValue(IntermediateFieldValue value) => value.AsPath();
39 {
40 return value.AsPath();
41 }
42 27
43 public static explicit operator string(IntermediateFieldValue value) 28 public static explicit operator string(IntermediateFieldValue value) => value.AsString();
44 {
45 return value.AsString();
46 }
47 29
48 internal static IntermediateFieldValue Deserialize(JsonObject jsonObject, Uri baseUri, IntermediateFieldType type) 30 internal static IntermediateFieldValue Deserialize(JsonObject jsonObject, Uri baseUri, IntermediateFieldType type)
49 { 31 {
diff --git a/src/WixToolset.Data/IntermediateTuple.cs b/src/WixToolset.Data/IntermediateTuple.cs
index 09ff7692..bc46e3b4 100644
--- a/src/WixToolset.Data/IntermediateTuple.cs
+++ b/src/WixToolset.Data/IntermediateTuple.cs
@@ -46,9 +46,9 @@ namespace WixToolset.Data
46 creator.TryGetTupleDefinitionByName(definitionName, out var definition); // TODO: this isn't sufficient. 46 creator.TryGetTupleDefinitionByName(definitionName, out var definition); // TODO: this isn't sufficient.
47 var tuple = definition.CreateTuple(sourceLineNumbers, id); 47 var tuple = definition.CreateTuple(sourceLineNumbers, id);
48 48
49 for (var i = 0; i < fieldsJson.Count; ++i) 49 for (var i = 0; i < fieldsJson.Count && i < tuple.Fields.Length; ++i)
50 { 50 {
51 if (tuple.Fields.Length > i && fieldsJson[i] is JsonObject fieldJson) 51 if (fieldsJson[i] is JsonObject fieldJson)
52 { 52 {
53 tuple.Fields[i] = IntermediateField.Deserialize(tuple.Definition.FieldDefinitions[i], baseUri, fieldJson); 53 tuple.Fields[i] = IntermediateField.Deserialize(tuple.Definition.FieldDefinitions[i], baseUri, fieldJson);
54 } 54 }
diff --git a/src/WixToolset.Data/IntermediateTupleExtensions.cs b/src/WixToolset.Data/IntermediateTupleExtensions.cs
index f5b30d47..dd488dc5 100644
--- a/src/WixToolset.Data/IntermediateTupleExtensions.cs
+++ b/src/WixToolset.Data/IntermediateTupleExtensions.cs
@@ -1,36 +1,26 @@
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. 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 2
3namespace WixToolset.Data 3namespace WixToolset.Data
4{ 4{
5 public static class IntermediateTupleExtensions 5 public static class IntermediateTupleExtensions
6 { 6 {
7 public static bool AsBool(this IntermediateTuple tuple, int index) 7 public static bool AsBool(this IntermediateTuple tuple, int index) => tuple?.Fields[index].AsBool() ?? false;
8 {
9 return tuple?.Fields[index].AsBool() ?? false;
10 }
11 8
12 public static bool? AsNullableBool(this IntermediateTuple tuple, int index) 9 public static bool? AsNullableBool(this IntermediateTuple tuple, int index) => tuple?.Fields[index].AsNullableBool();
13 {
14 return tuple?.Fields[index].AsNullableBool();
15 }
16 10
17 public static int AsNumber(this IntermediateTuple tuple, int index) 11 public static int AsNumber(this IntermediateTuple tuple, int index) => tuple?.Fields[index].AsNumber() ?? 0;
18 {
19 return tuple?.Fields[index].AsNumber() ?? 0;
20 }
21 12
22 public static int? AsNullableNumber(this IntermediateTuple tuple, int index) 13 public static int? AsNullableNumber(this IntermediateTuple tuple, int index) => tuple?.Fields[index].AsNullableNumber();
23 {
24 return tuple?.Fields[index].AsNullableNumber();
25 }
26 14
27 public static string AsString(this IntermediateTuple tuple, int index) 15 public static string AsString(this IntermediateTuple tuple, int index) => tuple?.Fields[index].AsString();
28 {
29 return tuple?.Fields[index].AsString();
30 }
31 16
32 public static IntermediateField Set(this IntermediateTuple tuple, int index, bool value) 17 public static IntermediateField Set(this IntermediateTuple tuple, int index, bool value)
33 { 18 {
19 if (value == default && NoFieldMetadata(tuple, index))
20 {
21 return tuple.Fields[index] = null;
22 }
23
34 var definition = tuple.Definition.FieldDefinitions[index]; 24 var definition = tuple.Definition.FieldDefinitions[index];
35 25
36 var field = tuple.Fields[index].Set(definition, value); 26 var field = tuple.Fields[index].Set(definition, value);
@@ -40,6 +30,11 @@ namespace WixToolset.Data
40 30
41 public static IntermediateField Set(this IntermediateTuple tuple, int index, bool? value) 31 public static IntermediateField Set(this IntermediateTuple tuple, int index, bool? value)
42 { 32 {
33 if (value == default && NoFieldMetadata(tuple, index))
34 {
35 return tuple.Fields[index] = null;
36 }
37
43 var definition = tuple.Definition.FieldDefinitions[index]; 38 var definition = tuple.Definition.FieldDefinitions[index];
44 39
45 var field = tuple.Fields[index].Set(definition, value); 40 var field = tuple.Fields[index].Set(definition, value);
@@ -49,6 +44,11 @@ namespace WixToolset.Data
49 44
50 public static IntermediateField Set(this IntermediateTuple tuple, int index, long value) 45 public static IntermediateField Set(this IntermediateTuple tuple, int index, long value)
51 { 46 {
47 if (value == default && NoFieldMetadata(tuple, index))
48 {
49 return tuple.Fields[index] = null;
50 }
51
52 var definition = tuple.Definition.FieldDefinitions[index]; 52 var definition = tuple.Definition.FieldDefinitions[index];
53 53
54 var field = tuple.Fields[index].Set(definition, value); 54 var field = tuple.Fields[index].Set(definition, value);
@@ -58,6 +58,11 @@ namespace WixToolset.Data
58 58
59 public static IntermediateField Set(this IntermediateTuple tuple, int index, long? value) 59 public static IntermediateField Set(this IntermediateTuple tuple, int index, long? value)
60 { 60 {
61 if (value == default && NoFieldMetadata(tuple, index))
62 {
63 return tuple.Fields[index] = null;
64 }
65
61 var definition = tuple.Definition.FieldDefinitions[index]; 66 var definition = tuple.Definition.FieldDefinitions[index];
62 67
63 var field = tuple.Fields[index].Set(definition, value); 68 var field = tuple.Fields[index].Set(definition, value);
@@ -67,6 +72,11 @@ namespace WixToolset.Data
67 72
68 public static IntermediateField Set(this IntermediateTuple tuple, int index, int value) 73 public static IntermediateField Set(this IntermediateTuple tuple, int index, int value)
69 { 74 {
75 if (value == default && NoFieldMetadata(tuple, index))
76 {
77 return tuple.Fields[index] = null;
78 }
79
70 var definition = tuple.Definition.FieldDefinitions[index]; 80 var definition = tuple.Definition.FieldDefinitions[index];
71 81
72 var field = tuple.Fields[index].Set(definition, value); 82 var field = tuple.Fields[index].Set(definition, value);
@@ -76,6 +86,11 @@ namespace WixToolset.Data
76 86
77 public static IntermediateField Set(this IntermediateTuple tuple, int index, int? value) 87 public static IntermediateField Set(this IntermediateTuple tuple, int index, int? value)
78 { 88 {
89 if (value == default && NoFieldMetadata(tuple, index))
90 {
91 return tuple.Fields[index] = null;
92 }
93
79 var definition = tuple.Definition.FieldDefinitions[index]; 94 var definition = tuple.Definition.FieldDefinitions[index];
80 95
81 var field = tuple.Fields[index].Set(definition, value); 96 var field = tuple.Fields[index].Set(definition, value);
@@ -85,6 +100,11 @@ namespace WixToolset.Data
85 100
86 public static IntermediateField Set(this IntermediateTuple tuple, int index, IntermediateFieldPathValue value) 101 public static IntermediateField Set(this IntermediateTuple tuple, int index, IntermediateFieldPathValue value)
87 { 102 {
103 if (value == default && NoFieldMetadata(tuple, index))
104 {
105 return tuple.Fields[index] = null;
106 }
107
88 var definition = tuple.Definition.FieldDefinitions[index]; 108 var definition = tuple.Definition.FieldDefinitions[index];
89 109
90 var field = tuple.Fields[index].Set(definition, value); 110 var field = tuple.Fields[index].Set(definition, value);
@@ -94,11 +114,23 @@ namespace WixToolset.Data
94 114
95 public static IntermediateField Set(this IntermediateTuple tuple, int index, string value) 115 public static IntermediateField Set(this IntermediateTuple tuple, int index, string value)
96 { 116 {
117 if (value == default && NoFieldMetadata(tuple, index))
118 {
119 return tuple.Fields[index] = null;
120 }
121
97 var definition = tuple.Definition.FieldDefinitions[index]; 122 var definition = tuple.Definition.FieldDefinitions[index];
98 123
99 var field = tuple.Fields[index].Set(definition, value); 124 var field = tuple.Fields[index].Set(definition, value);
100 125
101 return tuple.Fields[index] = field; 126 return tuple.Fields[index] = field;
102 } 127 }
128
129 private static bool NoFieldMetadata(IntermediateTuple tuple, int index)
130 {
131 var field = tuple?.Fields[index];
132
133 return field?.Context == null && field?.PreviousValue == null;
134 }
103 } 135 }
104} 136}
diff --git a/src/WixToolset.Data/Tuples/RemoveRegistryTuple.cs b/src/WixToolset.Data/Tuples/RemoveRegistryTuple.cs
index 42f15660..f4ec17bf 100644
--- a/src/WixToolset.Data/Tuples/RemoveRegistryTuple.cs
+++ b/src/WixToolset.Data/Tuples/RemoveRegistryTuple.cs
@@ -51,7 +51,7 @@ namespace WixToolset.Data.Tuples
51 51
52 public RegistryRootType Root 52 public RegistryRootType Root
53 { 53 {
54 get => (RegistryRootType)this.Fields[(int)RemoveRegistryTupleFields.Root]?.AsNumber(); 54 get => (RegistryRootType)this.Fields[(int)RemoveRegistryTupleFields.Root].AsNumber();
55 set => this.Set((int)RemoveRegistryTupleFields.Root, (int)value); 55 set => this.Set((int)RemoveRegistryTupleFields.Root, (int)value);
56 } 56 }
57 57
diff --git a/src/WixToolset.Data/Tuples/WixBundleTuple.cs b/src/WixToolset.Data/Tuples/WixBundleTuple.cs
index f7cd4f23..8f6f760a 100644
--- a/src/WixToolset.Data/Tuples/WixBundleTuple.cs
+++ b/src/WixToolset.Data/Tuples/WixBundleTuple.cs
@@ -32,7 +32,7 @@ namespace WixToolset.Data
32 new IntermediateFieldDefinition(nameof(WixBundleTupleFields.UpgradeCode), IntermediateFieldType.String), 32 new IntermediateFieldDefinition(nameof(WixBundleTupleFields.UpgradeCode), IntermediateFieldType.String),
33 new IntermediateFieldDefinition(nameof(WixBundleTupleFields.BundleId), IntermediateFieldType.String), 33 new IntermediateFieldDefinition(nameof(WixBundleTupleFields.BundleId), IntermediateFieldType.String),
34 new IntermediateFieldDefinition(nameof(WixBundleTupleFields.ProviderKey), IntermediateFieldType.String), 34 new IntermediateFieldDefinition(nameof(WixBundleTupleFields.ProviderKey), IntermediateFieldType.String),
35 new IntermediateFieldDefinition(nameof(WixBundleTupleFields.PerMachine), IntermediateFieldType.Number), 35 new IntermediateFieldDefinition(nameof(WixBundleTupleFields.PerMachine), IntermediateFieldType.Bool),
36 }, 36 },
37 typeof(WixBundleTuple)); 37 typeof(WixBundleTuple));
38 } 38 }
@@ -211,9 +211,9 @@ namespace WixToolset.Data.Tuples
211 set => this.Set((int)WixBundleTupleFields.ProviderKey, value); 211 set => this.Set((int)WixBundleTupleFields.ProviderKey, value);
212 } 212 }
213 213
214 public int PerMachine 214 public bool PerMachine
215 { 215 {
216 get => (int)this.Fields[(int)WixBundleTupleFields.PerMachine]; 216 get => (bool)this.Fields[(int)WixBundleTupleFields.PerMachine];
217 set => this.Set((int)WixBundleTupleFields.PerMachine, value); 217 set => this.Set((int)WixBundleTupleFields.PerMachine, value);
218 } 218 }
219 } 219 }