From 0fcad7fb87bd10db16c57006fe24fdb8b7d0061a Mon Sep 17 00:00:00 2001 From: enricosada Date: Mon, 11 May 2015 14:38:52 +0200 Subject: [PATCH] add IDictionaryEnumerator --- src/fsharp/FSharp.Core/fslib-extra-pervasives.fs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs b/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs index 60033fefd8b..83a6a87386d 100644 --- a/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs +++ b/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs @@ -39,6 +39,17 @@ module ExtraTopLevelOperators = t.[RuntimeHelpers.StructBox(k)] <- v let d = (t :> IDictionary<_,_>) let c = (t :> ICollection<_>) + + let dictEnumerator (a: System.Collections.Generic.IEnumerator) = + { new System.Collections.IDictionaryEnumerator with + member x.Current = a.Current :> obj + member x.Entry = a.Current + member x.Key = x.Entry.Key + member x.Value = x.Entry.Value + member x.MoveNext () = a.MoveNext() + member x.Reset () = a.Reset() + } + // Give a read-only view of the dictionary { new IDictionary<'Key, 'T> with member s.Item @@ -108,7 +119,8 @@ module ExtraTopLevelOperators = member s.Add(k,v) = raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated))) member s.Contains(k) = d.ContainsKey(RuntimeHelpers.StructBox(k :?> 'Key)) member s.GetEnumerator() = - ((c |> Seq.map (fun (KeyValue(k,v)) -> System.Collections.DictionaryEntry(k.Value,v))) :> System.Collections.IDictionary).GetEnumerator() + (c |> Seq.map (fun (KeyValue(k,v)) -> System.Collections.DictionaryEntry(k.Value,v))).GetEnumerator() + |> dictEnumerator member s.Remove(k) = (raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated))) : unit) member s.Clear() = raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated)));