diff options
Diffstat (limited to 'Xamarin.Forms.Core/ReadOnlyCastingList.cs')
-rw-r--r-- | Xamarin.Forms.Core/ReadOnlyCastingList.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/ReadOnlyCastingList.cs b/Xamarin.Forms.Core/ReadOnlyCastingList.cs new file mode 100644 index 00000000..a3f880c3 --- /dev/null +++ b/Xamarin.Forms.Core/ReadOnlyCastingList.cs @@ -0,0 +1,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; } + } + } +}
\ No newline at end of file |