aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-03-26 15:38:00 -0700
committerRob Mensching <rob@firegiant.com>2021-04-02 14:46:29 -0700
commita0dd2bc561ee6aa6b7aebedcff76c8a11e14bc9f (patch)
treee1dc86fa38fefde387e63aef9cfbb48d989aa853 /src
parentf7de7f52a790e989a42fc48935dc61c93f3f4137 (diff)
downloadwix-a0dd2bc561ee6aa6b7aebedcff76c8a11e14bc9f.tar.gz
wix-a0dd2bc561ee6aa6b7aebedcff76c8a11e14bc9f.tar.bz2
wix-a0dd2bc561ee6aa6b7aebedcff76c8a11e14bc9f.zip
Make the IntermediateSection and IntermediateSymbol less mutable
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.Data/Intermediate.cs2
-rw-r--r--src/WixToolset.Data/IntermediateSection.cs49
-rw-r--r--src/WixToolset.Data/IntermediateSectionExtensions.cs14
-rw-r--r--src/WixToolset.Data/IntermediateSymbol.cs53
-rw-r--r--src/WixToolset.Data/IntermediateSymbolDefinition.cs8
-rw-r--r--src/test/WixToolsetTest.Data/SerializeFixture.cs18
6 files changed, 105 insertions, 39 deletions
diff --git a/src/WixToolset.Data/Intermediate.cs b/src/WixToolset.Data/Intermediate.cs
index f9d33839..05ffdbf6 100644
--- a/src/WixToolset.Data/Intermediate.cs
+++ b/src/WixToolset.Data/Intermediate.cs
@@ -47,7 +47,7 @@ namespace WixToolset.Data
47 public string Id { get; } 47 public string Id { get; }
48 48
49 /// <summary> 49 /// <summary>
50 /// Get the id for the intermediate. 50 /// Get the level of the intermediate.
51 /// </summary> 51 /// </summary>
52 public string Level { get; private set; } 52 public string Level { get; private set; }
53 53
diff --git a/src/WixToolset.Data/IntermediateSection.cs b/src/WixToolset.Data/IntermediateSection.cs
index cd001d5c..86aa0c89 100644
--- a/src/WixToolset.Data/IntermediateSection.cs
+++ b/src/WixToolset.Data/IntermediateSection.cs
@@ -11,18 +11,22 @@ namespace WixToolset.Data
11 /// </summary> 11 /// </summary>
12 public class IntermediateSection 12 public class IntermediateSection
13 { 13 {
14 private readonly List<IntermediateSymbol> symbols;
15
14 /// <summary> 16 /// <summary>
15 /// Creates a new section as part of an intermediate. 17 /// Creates a new section as part of an intermediate.
16 /// </summary> 18 /// </summary>
17 /// <param name="id">Identifier for section.</param> 19 /// <param name="id">Identifier for section.</param>
18 /// <param name="type">Type of section.</param> 20 /// <param name="type">Type of section.</param>
19 /// <param name="codepage">Codepage for resulting database.</param> 21 /// <param name="codepage">Codepage for resulting database.</param>
20 public IntermediateSection(string id, SectionType type, int codepage) 22 /// <param name="compilationId">Optional compilation identifier</param>
23 public IntermediateSection(string id, SectionType type, int codepage, string compilationId = null)
21 { 24 {
22 this.Id = id; 25 this.Id = id;
23 this.Type = type; 26 this.Type = type;
24 this.Codepage = codepage; 27 this.Codepage = codepage;
25 this.Symbols = new List<IntermediateSymbol>(); 28 this.CompilationId = compilationId;
29 this.symbols = new List<IntermediateSymbol>();
26 } 30 }
27 31
28 /// <summary> 32 /// <summary>
@@ -41,22 +45,53 @@ namespace WixToolset.Data
41 /// Gets the codepage for the section. 45 /// Gets the codepage for the section.
42 /// </summary> 46 /// </summary>
43 /// <value>Codepage for the section.</value> 47 /// <value>Codepage for the section.</value>
44 public int Codepage { get; set; } 48 public int Codepage { get; }
45 49
46 /// <summary> 50 /// <summary>
47 /// Gets and sets the identifier of the compilation of the source file containing the section. 51 /// Gets and sets the identifier of the compilation of the source file containing the section.
48 /// </summary> 52 /// </summary>
49 public string CompilationId { get; set; } 53 public string CompilationId { get; }
50 54
51 /// <summary> 55 /// <summary>
52 /// Gets and sets the identifier of the library that combined the section. 56 /// Gets and sets the identifier of the library that combined the section.
53 /// </summary> 57 /// </summary>
54 public string LibraryId { get; set; } 58 public string LibraryId { get; private set; }
55 59
56 /// <summary> 60 /// <summary>
57 /// Symbols in the section. 61 /// Symbols in the section.
58 /// </summary> 62 /// </summary>
59 public IList<IntermediateSymbol> Symbols { get; } 63 public IReadOnlyCollection<IntermediateSymbol> Symbols => this.symbols;
64
65 /// <summary>
66 /// Adds a symbol to the section.
67 /// </summary>
68 /// <typeparam name="T">Type of IntermediateSymbol to add to the section.</typeparam>
69 /// <param name="symbol">Symbol to add to the section.</param>
70 /// <returns>Symbol added to the section.</returns>
71 public T AddSymbol<T>(T symbol) where T : IntermediateSymbol
72 {
73 this.symbols.Add(symbol);
74 return symbol;
75 }
76
77 /// <summary>
78 /// Assigns the section to a library.
79 /// </summary>
80 /// <param name="libraryId">Identifier of the library.</param>
81 public void AssignToLibrary(string libraryId)
82 {
83 this.LibraryId = libraryId;
84 }
85
86 /// <summary>
87 /// Removes a symbol from the section.
88 /// </summary>
89 /// <param name="symbol">Symbol to remove.</param>
90 /// <returns>True if the symbol was removed; otherwise false.</returns>
91 public bool RemoveSymbol(IntermediateSymbol symbol)
92 {
93 return this.symbols.Remove(symbol);
94 }
60 95
61 /// <summary> 96 /// <summary>
62 /// Parse a section from the JSON data. 97 /// Parse a section from the JSON data.
@@ -79,7 +114,7 @@ namespace WixToolset.Data
79 foreach (JsonObject symbolJson in symbolsJson) 114 foreach (JsonObject symbolJson in symbolsJson)
80 { 115 {
81 var symbol = IntermediateSymbol.Deserialize(creator, baseUri, symbolJson); 116 var symbol = IntermediateSymbol.Deserialize(creator, baseUri, symbolJson);
82 section.Symbols.Add(symbol); 117 section.symbols.Add(symbol);
83 } 118 }
84 119
85 return section; 120 return section;
diff --git a/src/WixToolset.Data/IntermediateSectionExtensions.cs b/src/WixToolset.Data/IntermediateSectionExtensions.cs
deleted file mode 100644
index 80e64eaa..00000000
--- a/src/WixToolset.Data/IntermediateSectionExtensions.cs
+++ /dev/null
@@ -1,14 +0,0 @@
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
3namespace WixToolset.Data
4{
5 public static class IntermediateSectionExtensions
6 {
7 public static T AddSymbol<T>(this IntermediateSection section, T symbol)
8 where T : IntermediateSymbol
9 {
10 section.Symbols.Add(symbol);
11 return symbol;
12 }
13 }
14}
diff --git a/src/WixToolset.Data/IntermediateSymbol.cs b/src/WixToolset.Data/IntermediateSymbol.cs
index 408be37c..4be17094 100644
--- a/src/WixToolset.Data/IntermediateSymbol.cs
+++ b/src/WixToolset.Data/IntermediateSymbol.cs
@@ -6,15 +6,28 @@ namespace WixToolset.Data
6 using System.Diagnostics; 6 using System.Diagnostics;
7 using SimpleJson; 7 using SimpleJson;
8 8
9 /// <summary>
10 /// Intermediate symbol.
11 /// </summary>
9 [DebuggerDisplay("{DebuggerDisplay,nq}")] 12 [DebuggerDisplay("{DebuggerDisplay,nq}")]
10 public class IntermediateSymbol 13 public class IntermediateSymbol
11 { 14 {
12 private object tags; 15 private object tags;
13 16
17 /// <summary>
18 /// Creates an intermediate symbol.
19 /// </summary>
20 /// <param name="definition">Symbol definition.</param>
14 public IntermediateSymbol(IntermediateSymbolDefinition definition) : this(definition, null, null) 21 public IntermediateSymbol(IntermediateSymbolDefinition definition) : this(definition, null, null)
15 { 22 {
16 } 23 }
17 24
25 /// <summary>
26 /// Creates an intermediate symbol with source line number and identifier.
27 /// </summary>
28 /// <param name="definition">Symbol definition.</param>
29 /// <param name="sourceLineNumber">Source line number.</param>
30 /// <param name="id">Symbol identifier.</param>
18 public IntermediateSymbol(IntermediateSymbolDefinition definition, SourceLineNumber sourceLineNumber, Identifier id = null) 31 public IntermediateSymbol(IntermediateSymbolDefinition definition, SourceLineNumber sourceLineNumber, Identifier id = null)
19 { 32 {
20 this.Definition = definition; 33 this.Definition = definition;
@@ -23,18 +36,40 @@ namespace WixToolset.Data
23 this.Id = id; 36 this.Id = id;
24 } 37 }
25 38
39 /// <summary>
40 /// Gets the symbol's definition.
41 /// </summary>
26 public IntermediateSymbolDefinition Definition { get; } 42 public IntermediateSymbolDefinition Definition { get; }
27 43
44 /// <summary>
45 /// Gets the symbol's fields.
46 /// </summary>
28 public IntermediateField[] Fields { get; } 47 public IntermediateField[] Fields { get; }
29 48
30 public SourceLineNumber SourceLineNumbers { get; set; } 49 /// <summary>
31 50 /// Gets the optional source line number of the symbol.
32 public Identifier Id { get; set; } 51 /// </summary>
33 52 public SourceLineNumber SourceLineNumbers { get; internal set; }
53
54 /// <summary>
55 /// Gets the optional identifier for the symbol.
56 /// </summary>
57 public Identifier Id { get; internal set; }
58
59 /// <summary>
60 /// Direct access by index to the symbol's fields.
61 /// </summary>
62 /// <param name="index">Index of the field to access.</param>
63 /// <returns>Symbol's field.</returns>
34 public IntermediateField this[int index] => this.Fields[index]; 64 public IntermediateField this[int index] => this.Fields[index];
35 65
36 private string DebuggerDisplay => $"{this.Definition?.Name} {this.Id?.Id}"; 66 private string DebuggerDisplay => $"{this.Definition?.Name} {this.Id?.Id}";
37 67
68 /// <summary>
69 /// Add a custom tag to the symbol.
70 /// </summary>
71 /// <param name="add">String tag to add to the symbol.</param>
72 /// <returns>True if the tag was added; otherwise false if th tag was already present.</returns>
38 public bool AddTag(string add) 73 public bool AddTag(string add)
39 { 74 {
40 if (this.tags == null) 75 if (this.tags == null)
@@ -73,6 +108,11 @@ namespace WixToolset.Data
73 return true; 108 return true;
74 } 109 }
75 110
111 /// <summary>
112 /// Tests whether a symbol has a tag.
113 /// </summary>
114 /// <param name="has">String tag to find.</param>
115 /// <returns>True if the symbol has the tag; otherwise false.</returns>
76 public bool HasTag(string has) 116 public bool HasTag(string has)
77 { 117 {
78 if (this.tags == null) 118 if (this.tags == null)
@@ -97,6 +137,11 @@ namespace WixToolset.Data
97 return false; 137 return false;
98 } 138 }
99 139
140 /// <summary>
141 /// Removes a tag from the symbol.
142 /// </summary>
143 /// <param name="remove">String tag to remove.</param>
144 /// <returns>True if the tag was removed; otherwise false if the tag was not present.</returns>
100 public bool RemoveTag(string remove) 145 public bool RemoveTag(string remove)
101 { 146 {
102 if (this.tags is string tag) 147 if (this.tags is string tag)
diff --git a/src/WixToolset.Data/IntermediateSymbolDefinition.cs b/src/WixToolset.Data/IntermediateSymbolDefinition.cs
index 102a9f5c..dc913704 100644
--- a/src/WixToolset.Data/IntermediateSymbolDefinition.cs
+++ b/src/WixToolset.Data/IntermediateSymbolDefinition.cs
@@ -48,11 +48,11 @@ namespace WixToolset.Data
48 48
49 public IntermediateSymbol CreateSymbol(SourceLineNumber sourceLineNumber = null, Identifier id = null) 49 public IntermediateSymbol CreateSymbol(SourceLineNumber sourceLineNumber = null, Identifier id = null)
50 { 50 {
51 var result = (this.StrongSymbolType == typeof(IntermediateSymbol)) ? (IntermediateSymbol)Activator.CreateInstance(this.StrongSymbolType, this) : (IntermediateSymbol)Activator.CreateInstance(this.StrongSymbolType); 51 var symbol = (this.StrongSymbolType == typeof(IntermediateSymbol)) ? (IntermediateSymbol)Activator.CreateInstance(this.StrongSymbolType, this) : (IntermediateSymbol)Activator.CreateInstance(this.StrongSymbolType);
52 result.SourceLineNumbers = sourceLineNumber; 52 symbol.SourceLineNumbers = sourceLineNumber;
53 result.Id = id; 53 symbol.Id = id;
54 54
55 return result; 55 return symbol;
56 } 56 }
57 57
58 public bool AddTag(string add) 58 public bool AddTag(string add)
diff --git a/src/test/WixToolsetTest.Data/SerializeFixture.cs b/src/test/WixToolsetTest.Data/SerializeFixture.cs
index 56d08bc9..ff39cb33 100644
--- a/src/test/WixToolsetTest.Data/SerializeFixture.cs
+++ b/src/test/WixToolsetTest.Data/SerializeFixture.cs
@@ -22,7 +22,7 @@ namespace WixToolsetTest.Data
22 22
23 var section = new IntermediateSection("test", SectionType.Product, 65001); 23 var section = new IntermediateSection("test", SectionType.Product, 65001);
24 24
25 section.Symbols.Add(new ComponentSymbol(sln, new Identifier(AccessModifier.Global, "TestComponent")) 25 section.AddSymbol(new ComponentSymbol(sln, new Identifier(AccessModifier.Global, "TestComponent"))
26 { 26 {
27 ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"), 27 ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"),
28 DirectoryRef = "TestFolder", 28 DirectoryRef = "TestFolder",
@@ -64,7 +64,7 @@ namespace WixToolsetTest.Data
64 var sln = new SourceLineNumber("test.wxs", 1); 64 var sln = new SourceLineNumber("test.wxs", 1);
65 var section = new IntermediateSection("test", SectionType.Product, 65001); 65 var section = new IntermediateSection("test", SectionType.Product, 65001);
66 66
67 section.Symbols.Add(new ComponentSymbol(sln, new Identifier(AccessModifier.Global, "TestComponent")) 67 section.AddSymbol(new ComponentSymbol(sln, new Identifier(AccessModifier.Global, "TestComponent"))
68 { 68 {
69 ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"), 69 ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"),
70 DirectoryRef = "TestFolder", 70 DirectoryRef = "TestFolder",
@@ -91,7 +91,7 @@ namespace WixToolsetTest.Data
91 91
92 wixout.Reopen(writable: true); 92 wixout.Reopen(writable: true);
93 93
94 section.Symbols.Add(new ComponentSymbol(sln, new Identifier(AccessModifier.Global, "NewComponent")) 94 section.AddSymbol(new ComponentSymbol(sln, new Identifier(AccessModifier.Global, "NewComponent"))
95 { 95 {
96 ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"), 96 ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"),
97 }); 97 });
@@ -135,7 +135,7 @@ namespace WixToolsetTest.Data
135 symbol.Set(1, 2); 135 symbol.Set(1, 2);
136 symbol.Set(2, true); 136 symbol.Set(2, true);
137 137
138 section.Symbols.Add(symbol); 138 section.AddSymbol(symbol);
139 139
140 var intermediate = new Intermediate("TestIntermediate", new[] { section }, null); 140 var intermediate = new Intermediate("TestIntermediate", new[] { section }, null);
141 141
@@ -179,7 +179,7 @@ namespace WixToolsetTest.Data
179 symbol.Set(2, true); 179 symbol.Set(2, true);
180 180
181 var section = new IntermediateSection("test", SectionType.Product, 65001); 181 var section = new IntermediateSection("test", SectionType.Product, 65001);
182 section.Symbols.Add(symbol); 182 section.AddSymbol(symbol);
183 183
184 var intermediate1 = new Intermediate("TestIntermediate", new[] { section }, null); 184 var intermediate1 = new Intermediate("TestIntermediate", new[] { section }, null);
185 185
@@ -201,7 +201,7 @@ namespace WixToolsetTest.Data
201 symbol2.Set(3, "baz"); 201 symbol2.Set(3, "baz");
202 202
203 var section2 = new IntermediateSection("test2", SectionType.Fragment, 65001); 203 var section2 = new IntermediateSection("test2", SectionType.Fragment, 65001);
204 section2.Symbols.Add(symbol2); 204 section2.AddSymbol(symbol2);
205 205
206 var intermediate2 = new Intermediate("TestIntermediate2", new[] { section2 }, null); 206 var intermediate2 = new Intermediate("TestIntermediate2", new[] { section2 }, null);
207 207
@@ -262,7 +262,7 @@ namespace WixToolsetTest.Data
262 symbol.AddTag("symbol1tag"); 262 symbol.AddTag("symbol1tag");
263 263
264 var section = new IntermediateSection("test", SectionType.Product, 65001); 264 var section = new IntermediateSection("test", SectionType.Product, 65001);
265 section.Symbols.Add(symbol); 265 section.AddSymbol(symbol);
266 266
267 var intermediate1 = new Intermediate("TestIntermediate", new[] { section }, null); 267 var intermediate1 = new Intermediate("TestIntermediate", new[] { section }, null);
268 268
@@ -290,7 +290,7 @@ namespace WixToolsetTest.Data
290 symbol2.AddTag("symbol2tag2"); 290 symbol2.AddTag("symbol2tag2");
291 291
292 var section2 = new IntermediateSection("test2", SectionType.Fragment, 65001); 292 var section2 = new IntermediateSection("test2", SectionType.Fragment, 65001);
293 section2.Symbols.Add(symbol2); 293 section2.AddSymbol(symbol2);
294 294
295 var intermediate2 = new Intermediate("TestIntermediate2", new[] { section2 }, null); 295 var intermediate2 = new Intermediate("TestIntermediate2", new[] { section2 }, null);
296 296
@@ -356,7 +356,7 @@ namespace WixToolsetTest.Data
356 356
357 var section = new IntermediateSection("test", SectionType.Product, 65001); 357 var section = new IntermediateSection("test", SectionType.Product, 65001);
358 358
359 section.Symbols.Add(new ComponentSymbol(sln, new Identifier(AccessModifier.Global, "TestComponent")) 359 section.AddSymbol(new ComponentSymbol(sln, new Identifier(AccessModifier.Global, "TestComponent"))
360 { 360 {
361 ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"), 361 ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"),
362 DirectoryRef = "TestFolder", 362 DirectoryRef = "TestFolder",