// 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;
}
}
}