Skip to content

Commit

Permalink
Merge pull request dotnet#2 from enricosada/pr_436_dict
Browse files Browse the repository at this point in the history
add IDictionaryEnumerator
  • Loading branch information
forki committed May 11, 2015
2 parents dba8190 + 0fcad7f commit e51598a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/fsharp/FSharp.Core/fslib-extra-pervasives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<System.Collections.DictionaryEntry>) =
{ 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
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit e51598a

Please sign in to comment.