Open rstm-sf opened 4 years ago
Since collection is guaranteed to be append-only, we should probably use a specialized enumerator there, e. g.
struct AppendOnlyListEnumerator<T> : IEnumerator<T>
{
private readonly IReadOnlyList<T> _list;
private int _index;
public AppendOnlyListEnumerator(IReadOnlyList<T> list)
{
_list = list;
_index = -1;
}
public bool MoveNext()
{
if (_list.Count > _index + 1)
{
_index++;
return true;
}
return false;
}
public void Reset() => _index = -1;
public T Current => _list[_index];
object IEnumerator.Current => Current;
public void Dispose()
{
}
}
struct AppendOnlyEnumerable<T> : IEnumerable<T>
{
private readonly IReadOnlyList<T> _list;
public AppendOnlyEnumerable(IReadOnlyList<T> list)
{
_list = list;
}
public IEnumerator<T> GetEnumerator()
{
return new AppendOnlyListEnumerator<T>(_list);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
static class ListExtensions
{
public static AppendOnlyEnumerable<T> EnumerateAsAppendOnly<T>(this List<T> list) =>
new AppendOnlyEnumerable<T>(list);
}
Can we replace IReadOnlyList with IEnumerable in a similar way?
Hello!
XamlParserTests crashes with dotnet test exception for net47
If you write
ToList()
here, then everything will be fine https://github.com/kekekeks/XamlX/blob/697a419675a8055b7ef9a1904360359522b30616/src/XamlX/IL/SreTypeSystem.cs#L18Unlike #33, here it seems to me that the problem of the main library