Created
December 14, 2020 00:47
-
-
Save MiffOttah/a4a7713f529c8bbfd87728e699faf39e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// never use this btw | |
public class StarWarsList<T> : IList<T> | |
{ | |
private readonly List<T> _BaseList = new List<T>(); | |
private static int _FromStarWarsNumbering(int i) => i switch | |
{ | |
4 => 0, | |
5 => 1, | |
6 => 2, | |
1 => 3, | |
2 => 4, | |
3 => 5, | |
_ => i - 1 | |
}; | |
private static int _ToStarWarsNumbering(int i) => i switch | |
{ | |
0 => 4, | |
1 => 5, | |
2 => 6, | |
3 => 1, | |
4 => 2, | |
5 => 3, | |
-1 => -1, // required for IndexOf | |
_ => i + 1 | |
}; | |
public T this[int index] | |
{ | |
get => _BaseList[_FromStarWarsNumbering(index)]; | |
set => _BaseList[_ToStarWarsNumbering(index)] = value; | |
} | |
public int Count => _BaseList.Count; | |
bool ICollection<T>.IsReadOnly => ((ICollection<T>)_BaseList).IsReadOnly; | |
public void Add(T item) => _BaseList.Add(item); | |
public void Clear() => _BaseList.Clear(); | |
public bool Contains(T item) => _BaseList.Contains(item); | |
public void CopyTo(T[] array, int arrayIndex) => _BaseList.CopyTo(array, arrayIndex); | |
public int IndexOf(T item) => _ToStarWarsNumbering(_BaseList.IndexOf(item)); | |
public void Insert(int index, T item) => _BaseList.Insert(_FromStarWarsNumbering(index), item); | |
public bool Remove(T item) => _BaseList.Remove(item); | |
public void RemoveAt(int index) => _BaseList.RemoveAt(_FromStarWarsNumbering(index)); | |
public IEnumerator<T> GetEnumerator() => _BaseList.GetEnumerator(); | |
IEnumerator IEnumerable.GetEnumerator() => _BaseList.GetEnumerator(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment