summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/ReadOnlyCastingList.cs
blob: a3f880c341b8b49d1af65cde65d8e704b2b525c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections;
using System.Collections.Generic;

namespace Xamarin.Forms
{
	internal class ReadOnlyCastingList<T, TFrom> : IReadOnlyList<T> where T : class where TFrom : class
	{
		readonly IList<TFrom> _list;

		public ReadOnlyCastingList(IList<TFrom> list)
		{
			_list = list;
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable)_list).GetEnumerator();
		}

		public IEnumerator<T> GetEnumerator()
		{
			return new CastingEnumerator<T, TFrom>(_list.GetEnumerator());
		}

		public int Count
		{
			get { return _list.Count; }
		}

		public T this[int index]
		{
			get { return _list[index] as T; }
		}
	}
}