Skip to content

Commit 0fcad7f

Browse files
committed
add IDictionaryEnumerator
1 parent dba8190 commit 0fcad7f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/fsharp/FSharp.Core/fslib-extra-pervasives.fs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ module ExtraTopLevelOperators =
3939
t.[RuntimeHelpers.StructBox(k)] <- v
4040
let d = (t :> IDictionary<_,_>)
4141
let c = (t :> ICollection<_>)
42+
43+
let dictEnumerator (a: System.Collections.Generic.IEnumerator<System.Collections.DictionaryEntry>) =
44+
{ new System.Collections.IDictionaryEnumerator with
45+
member x.Current = a.Current :> obj
46+
member x.Entry = a.Current
47+
member x.Key = x.Entry.Key
48+
member x.Value = x.Entry.Value
49+
member x.MoveNext () = a.MoveNext()
50+
member x.Reset () = a.Reset()
51+
}
52+
4253
// Give a read-only view of the dictionary
4354
{ new IDictionary<'Key, 'T> with
4455
member s.Item
@@ -108,7 +119,8 @@ module ExtraTopLevelOperators =
108119
member s.Add(k,v) = raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated)))
109120
member s.Contains(k) = d.ContainsKey(RuntimeHelpers.StructBox(k :?> 'Key))
110121
member s.GetEnumerator() =
111-
((c |> Seq.map (fun (KeyValue(k,v)) -> System.Collections.DictionaryEntry(k.Value,v))) :> System.Collections.IDictionary).GetEnumerator()
122+
(c |> Seq.map (fun (KeyValue(k,v)) -> System.Collections.DictionaryEntry(k.Value,v))).GetEnumerator()
123+
|> dictEnumerator
112124

113125
member s.Remove(k) = (raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated))) : unit)
114126
member s.Clear() = raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated)));

0 commit comments

Comments
 (0)