From 49f1209035aac1fcfad5dbbe25f7b2306d3be86c Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 7 Dec 2017 14:19:05 -0800 Subject: Support MSI backends creating custom tables and remove WixToolset.Data.WindowsInstaller --- .../RowDictionary.cs | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/WixToolset.Core.WindowsInstaller/RowDictionary.cs (limited to 'src/WixToolset.Core.WindowsInstaller/RowDictionary.cs') 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 @@ +// 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. + +namespace WixToolset.Core.WindowsInstaller +{ + using System; + using System.Collections.Generic; + using WixToolset.Data.WindowsInstaller; + + /// + /// A dictionary of rows. Unlike the this + /// will throw when multiple rows with the same key are added. + /// + public sealed class RowDictionary : Dictionary where T : Row + { + /// + /// Creates an empty . + /// + public RowDictionary() + : base(StringComparer.InvariantCulture) + { + } + + /// + /// Creates and populates a with the rows from the given enumerator. + /// + /// Rows to add. + public RowDictionary(IEnumerable rows) + : this() + { + foreach (T row in rows) + { + this.Add(row); + } + } + + /// + /// Creates and populates a with the rows from the given . + /// + /// The table to index. + /// + /// Rows added to the index are not automatically added to the given . + /// + public RowDictionary(Table table) + : this() + { + if (null != table) + { + foreach (T row in table.Rows) + { + this.Add(row); + } + } + } + + /// + /// Adds a row to the dictionary using the row key. + /// + /// Row to add to the dictionary. + public void Add(T row) + { + this.Add(row.GetKey(), row); + } + + /// + /// Gets the row by integer key. + /// + /// Integer key to look up. + /// Row or null if key is not found. + public T Get(int key) + { + return this.Get(key.ToString()); + } + + /// + /// Gets the row by string key. + /// + /// String key to look up. + /// Row or null if key is not found. + public T Get(string key) + { + return this.TryGetValue(key, out var result) ? result : null; + } + } +} -- cgit v1.2.3-55-g6feb