* Apply R# clean-up for reliability - Migrate to NUnit4 Assert.That - Update dependencise versions - Fix LangVersion to 9.0 (until net core migration) - Reformat code - Apply 'var' style (easier for refactoring) - Remove redundant parentheses - Add braces on every condition blocks (1 line) - Uses new null checking patterns - Uses AutoProperties when possible - Uses string scalar type instead of class - Clean usings - Add .orig files in git ignore - Rename some properties to respect defined conventions and US format definition - ID -> Id - BPM -> Bpm - Finish -> End * Update R# settings according to the clean-up made
108 lines
2.9 KiB
C#
108 lines
2.9 KiB
C#
#region license
|
|
// This file is part of Vocaluxe.
|
|
//
|
|
// Vocaluxe is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Vocaluxe is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
|
#endregion
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using VocaluxeLib.Log;
|
|
|
|
namespace VocaluxeLib.Menu
|
|
{
|
|
public class COrderedDictionaryLite<T> : IEnumerable<T>
|
|
{
|
|
private readonly List<T> _Items;
|
|
private readonly Dictionary<String, int> _HtIndex;
|
|
private readonly String _ParentName;
|
|
|
|
public COrderedDictionaryLite(object parent)
|
|
{
|
|
_Items = new List<T>();
|
|
_HtIndex = new Dictionary<String, int>();
|
|
_ParentName = parent.GetType().Name;
|
|
if (_ParentName[0] == 'C' && Char.IsUpper(_ParentName[1]))
|
|
{
|
|
_ParentName = _ParentName.Remove(0, 1);
|
|
}
|
|
}
|
|
|
|
public int Count
|
|
{
|
|
get { return _Items.Count; }
|
|
}
|
|
|
|
public T this[int index]
|
|
{
|
|
get { return _Items[index]; }
|
|
set { _Items[index] = value; }
|
|
}
|
|
|
|
public T this[string key]
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
return _Items[_HtIndex[key]];
|
|
}
|
|
catch (Exception)
|
|
{
|
|
CLog.Error("Can't find " + typeof(T).Name.Substring(1) + " Element \"" + key + "\" in " + _ParentName);
|
|
throw;
|
|
}
|
|
}
|
|
set
|
|
{
|
|
if (!_HtIndex.ContainsKey(key))
|
|
{
|
|
_HtIndex.Add(key, _Items.Count);
|
|
_Items.Add(value);
|
|
}
|
|
else
|
|
{
|
|
_Items[_HtIndex[key]] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int Add(T item, String key = null)
|
|
{
|
|
if (key != null)
|
|
{
|
|
_HtIndex.Add(key, _Items.Count);
|
|
}
|
|
|
|
_Items.Add(item);
|
|
return _Items.Count - 1;
|
|
}
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
return _Items.GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_HtIndex.Clear();
|
|
_Items.Clear();
|
|
}
|
|
}
|
|
} |