diff options
Diffstat (limited to 'Xamarin.Forms.Core/CastingEnumerator.cs')
-rw-r--r-- | Xamarin.Forms.Core/CastingEnumerator.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/CastingEnumerator.cs b/Xamarin.Forms.Core/CastingEnumerator.cs new file mode 100644 index 00000000..62a823b1 --- /dev/null +++ b/Xamarin.Forms.Core/CastingEnumerator.cs @@ -0,0 +1,46 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Xamarin.Forms +{ + internal class CastingEnumerator<T, TFrom> : IEnumerator<T> where T : class where TFrom : class + { + readonly IEnumerator<TFrom> _enumerator; + + bool _disposed; + + public CastingEnumerator(IEnumerator<TFrom> enumerator) + { + _enumerator = enumerator; + } + + public void Dispose() + { + if (_disposed) + return; + _disposed = true; + + _enumerator.Dispose(); + } + + object IEnumerator.Current + { + get { return Current; } + } + + public bool MoveNext() + { + return _enumerator.MoveNext(); + } + + public void Reset() + { + _enumerator.Reset(); + } + + public T Current + { + get { return _enumerator.Current as T; } + } + } +}
\ No newline at end of file |