38 lines
996 B
C#
Raw Permalink Normal View History

2019-06-12 21:56:55 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Capnp
{
/// <summary>
/// Implements an empty <see cref="IReadOnlyList{T}"/>.
/// </summary>
2020-03-01 17:56:14 +01:00
/// <typeparam name="T">list element type</typeparam>
2019-06-12 21:56:55 +02:00
public class EmptyList<T> : IReadOnlyList<T>
{
/// <summary>
2020-03-01 17:56:14 +01:00
/// Always throws an <see cref="IndexOutOfRangeException"/>.
2019-06-12 21:56:55 +02:00
/// </summary>
/// <param name="index">Ignored</param>
2020-03-01 17:56:14 +01:00
public T this[int index] => throw new IndexOutOfRangeException(nameof(index));
2019-06-12 21:56:55 +02:00
/// <summary>
/// Always 0.
/// </summary>
public int Count => 0;
/// <summary>
/// Returns an empty enumerator.
/// </summary>
public IEnumerator<T> GetEnumerator()
{
return Enumerable.Empty<T>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
2020-01-11 17:56:12 +01:00
}