using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Capnp
{
///
/// ListDeserializer specialization for List(Void).
///
public class ListOfEmptyDeserializer : ListDeserializer, IReadOnlyList
{
internal ListOfEmptyDeserializer(in DeserializerState state) :
base(state)
{
}
///
/// Returns a DeserializerState representing an element at given index.
/// This is always the null object, since Void cannot carry any data.
///
/// Element index
/// default(DeserializerState)
/// is out of range.
public DeserializerState this[int index]
{
get
{
if (index < 0 || index >= Count)
throw new IndexOutOfRangeException();
return default;
}
}
///
/// Always ListKind.ListOfEmpty
///
public override ListKind Kind => ListKind.ListOfEmpty;
///
/// Applies a selector function to each element.
/// Trivia: Since each element is the null object, the selector function always gets fed with a null object.
///
/// Element target type
/// Selector function
/// The desired representation
public override IReadOnlyList Cast(Func cons)
{
return this.LazyListSelect(cons);
}
///
/// Implements .
///
public IEnumerator GetEnumerator()
{
return Enumerable.Repeat(default(DeserializerState), Count).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}