From 221da62c05ef2b515eb507c77655514cd0ec32a4 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 7 Dec 2017 14:17:39 -0800 Subject: Reintegrate MSI constructs into WxToolset.Data.WindowsInstaller namespace --- .../WindowsInstaller/TableIndexedCollection.cs | 143 +++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/WixToolset.Data/WindowsInstaller/TableIndexedCollection.cs (limited to 'src/WixToolset.Data/WindowsInstaller/TableIndexedCollection.cs') diff --git a/src/WixToolset.Data/WindowsInstaller/TableIndexedCollection.cs b/src/WixToolset.Data/WindowsInstaller/TableIndexedCollection.cs new file mode 100644 index 00000000..1b7de72b --- /dev/null +++ b/src/WixToolset.Data/WindowsInstaller/TableIndexedCollection.cs @@ -0,0 +1,143 @@ +// 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.Data.WindowsInstaller +{ + using System.Collections.Generic; + using System.Linq; + + /// + /// Collection for tables. + /// + public sealed class TableIndexedCollection : ICollection + { + private Dictionary collection; + + /// + /// Instantiate a new empty collection. + /// + public TableIndexedCollection() + { + this.collection = new Dictionary(); + } + + /// + /// Instantiate a new collection populated with a set of tables. + /// + /// Set of tables. + public TableIndexedCollection(IEnumerable
tables) + { + this.collection = tables.ToDictionary(t => t.Name); + } + + /// + /// Gets the number of items in the collection. + /// + /// Number of items in collection. + public int Count => this.collection.Count; + + /// + /// Table indexed collection is never read only. + /// + public bool IsReadOnly => false; + + /// + /// Adds a table to the collection. + /// + /// Table to add to the collection. + /// Indexes the table by name. + public void Add(Table table) + { + this.collection.Add(table.Name, table); + } + + /// + /// Clear the tables from the collection. + /// + public void Clear() + { + this.collection.Clear(); + } + + /// + /// Determines if a table is in the collection. + /// + /// Table to check if it is in the collection. + /// True if the table name is in the collection, otherwise false. + public bool Contains(Table table) => this.collection.ContainsKey(table.Name); + + /// + /// Copies the collection into an array. + /// + /// Array to copy the collection into. + /// Index to start copying from. + public void CopyTo(Table[] array, int arrayIndex) + { + this.collection.Values.CopyTo(array, arrayIndex); + } + + /// + /// Remove a table from the collection by name. + /// + /// Table name to remove from the collection. + public void Remove(string tableName) + { + this.collection.Remove(tableName); + } + + /// + /// Remove a table from the collection. + /// + /// Table with matching name to remove from the collection. + public bool Remove(Table table) + { + return this.collection.Remove(table.Name); + } + + /// + /// Gets an enumerator over the whole collection. + /// + /// Collection enumerator. + public IEnumerator
GetEnumerator() + { + return this.collection.Values.GetEnumerator(); + } + + /// + /// Gets an untyped enumerator over the whole collection. + /// + /// Untyped collection enumerator. + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return this.collection.Values.GetEnumerator(); + } + + /// + /// Gets a table by name. + /// + /// Name of table to locate. + public Table this[string tableName] + { + get + { + Table table; + return this.collection.TryGetValue(tableName, out table) ? table : null; + } + + set + { + this.collection[tableName] = value; + } + } + + /// + /// Tries to find a table by name. + /// + /// Table name to locate. + /// Found table. + /// True if table with table name was found, otherwise false. + public bool TryGetTable(string tableName, out Table table) + { + return this.collection.TryGetValue(tableName, out table); + } + } +} -- cgit v1.2.3-55-g6feb