project structure changed
This commit is contained in:
77
Enumerable/EnumerableIList.cs
Normal file
77
Enumerable/EnumerableIList.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright (c) Ben A Adams. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace DTLib.Ben.Demystifier.Enumerable;
|
||||
|
||||
public static class EnumerableIList
|
||||
{
|
||||
public static EnumerableIList<T> Create<T>(IList<T> list)
|
||||
{
|
||||
return new(list);
|
||||
}
|
||||
}
|
||||
|
||||
public struct EnumerableIList<T> : IEnumerableIList<T>, IList<T>
|
||||
{
|
||||
private readonly IList<T> _list;
|
||||
|
||||
public EnumerableIList(IList<T> list) => _list = list;
|
||||
|
||||
public EnumeratorIList<T> GetEnumerator() => new(_list);
|
||||
|
||||
public static implicit operator EnumerableIList<T>(List<T> list) => new(list);
|
||||
|
||||
public static implicit operator EnumerableIList<T>(T[] array) => new(array);
|
||||
|
||||
public static EnumerableIList<T> Empty = default;
|
||||
|
||||
|
||||
// IList pass through
|
||||
|
||||
/// <inheritdoc />
|
||||
public T this[int index]
|
||||
{
|
||||
get => _list[index];
|
||||
set => _list[index] = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count => _list.Count;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsReadOnly => _list.IsReadOnly;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Add(T item) => _list.Add(item);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Clear() => _list.Clear();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Contains(T item) => _list.Contains(item);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(T[] array, int arrayIndex) => _list.CopyTo(array, arrayIndex);
|
||||
|
||||
/// <inheritdoc />
|
||||
public int IndexOf(T item) => _list.IndexOf(item);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Insert(int index, T item) => _list.Insert(index, item);
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Remove(T item) => _list.Remove(item);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveAt(int index) => _list.RemoveAt(index);
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
35
Enumerable/EnumeratorIList.cs
Normal file
35
Enumerable/EnumeratorIList.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) Ben A Adams. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace DTLib.Ben.Demystifier.Enumerable;
|
||||
|
||||
public struct EnumeratorIList<T> : IEnumerator<T>
|
||||
{
|
||||
private readonly IList<T> _list;
|
||||
private int _index;
|
||||
|
||||
public EnumeratorIList(IList<T> list)
|
||||
{
|
||||
_index = -1;
|
||||
_list = list;
|
||||
}
|
||||
|
||||
public T Current => _list[_index];
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
_index++;
|
||||
|
||||
return _index < (_list?.Count ?? 0);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{ }
|
||||
|
||||
object? IEnumerator.Current => Current;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_index = -1;
|
||||
}
|
||||
}
|
||||
9
Enumerable/IEnumerableIList.cs
Normal file
9
Enumerable/IEnumerableIList.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) Ben A Adams. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace DTLib.Ben.Demystifier.Enumerable;
|
||||
|
||||
internal interface IEnumerableIList<T> : IEnumerable<T>
|
||||
{
|
||||
new EnumeratorIList<T> GetEnumerator();
|
||||
}
|
||||
Reference in New Issue
Block a user