diff options
author | Rob Mensching <rob@firegiant.com> | 2017-12-07 14:19:05 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2017-12-07 14:19:05 -0800 |
commit | 49f1209035aac1fcfad5dbbe25f7b2306d3be86c (patch) | |
tree | 6ce5921493eb751b6d89c3faf0ebdf64110cbb65 /src/WixToolset.Core.WindowsInstaller/RowDictionary.cs | |
parent | b1e662bd480241ea914f0f3d6bd174d9ffd03f5f (diff) | |
download | wix-49f1209035aac1fcfad5dbbe25f7b2306d3be86c.tar.gz wix-49f1209035aac1fcfad5dbbe25f7b2306d3be86c.tar.bz2 wix-49f1209035aac1fcfad5dbbe25f7b2306d3be86c.zip |
Support MSI backends creating custom tables and remove WixToolset.Data.WindowsInstaller
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/RowDictionary.cs')
-rw-r--r-- | src/WixToolset.Core.WindowsInstaller/RowDictionary.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/RowDictionary.cs b/src/WixToolset.Core.WindowsInstaller/RowDictionary.cs new file mode 100644 index 00000000..101ebefd --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/RowDictionary.cs | |||
@@ -0,0 +1,84 @@ | |||
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 WixToolset.Core.WindowsInstaller | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using WixToolset.Data.WindowsInstaller; | ||
8 | |||
9 | /// <summary> | ||
10 | /// A dictionary of rows. Unlike the <see cref="RowIndexedCollection"/> this | ||
11 | /// will throw when multiple rows with the same key are added. | ||
12 | /// </summary> | ||
13 | public sealed class RowDictionary<T> : Dictionary<string, T> where T : Row | ||
14 | { | ||
15 | /// <summary> | ||
16 | /// Creates an empty <see cref="RowDictionary"/>. | ||
17 | /// </summary> | ||
18 | public RowDictionary() | ||
19 | : base(StringComparer.InvariantCulture) | ||
20 | { | ||
21 | } | ||
22 | |||
23 | /// <summary> | ||
24 | /// Creates and populates a <see cref="RowDictionary"/> with the rows from the given enumerator. | ||
25 | /// </summary> | ||
26 | /// <param name="Rows">Rows to add.</param> | ||
27 | public RowDictionary(IEnumerable<T> rows) | ||
28 | : this() | ||
29 | { | ||
30 | foreach (T row in rows) | ||
31 | { | ||
32 | this.Add(row); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | /// <summary> | ||
37 | /// Creates and populates a <see cref="RowDictionary"/> with the rows from the given <see cref="Table"/>. | ||
38 | /// </summary> | ||
39 | /// <param name="table">The table to index.</param> | ||
40 | /// <remarks> | ||
41 | /// Rows added to the index are not automatically added to the given <paramref name="table"/>. | ||
42 | /// </remarks> | ||
43 | public RowDictionary(Table table) | ||
44 | : this() | ||
45 | { | ||
46 | if (null != table) | ||
47 | { | ||
48 | foreach (T row in table.Rows) | ||
49 | { | ||
50 | this.Add(row); | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /// <summary> | ||
56 | /// Adds a row to the dictionary using the row key. | ||
57 | /// </summary> | ||
58 | /// <param name="row">Row to add to the dictionary.</param> | ||
59 | public void Add(T row) | ||
60 | { | ||
61 | this.Add(row.GetKey(), row); | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
65 | /// Gets the row by integer key. | ||
66 | /// </summary> | ||
67 | /// <param name="key">Integer key to look up.</param> | ||
68 | /// <returns>Row or null if key is not found.</returns> | ||
69 | public T Get(int key) | ||
70 | { | ||
71 | return this.Get(key.ToString()); | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// Gets the row by string key. | ||
76 | /// </summary> | ||
77 | /// <param name="key">String key to look up.</param> | ||
78 | /// <returns>Row or null if key is not found.</returns> | ||
79 | public T Get(string key) | ||
80 | { | ||
81 | return this.TryGetValue(key, out var result) ? result : null; | ||
82 | } | ||
83 | } | ||
84 | } | ||