Public Class Functions
Public Shared Function ReverseDictionary(Of TKey, TVal)(ByVal dict As Dictionary(Of TKey, TVal)) As Dictionary(Of TKey, TVal)
' .NET objectmodel sucks. This is only to compensate for the
' lack of a Dictionary(Of TKey, TVal).reverse() functionality
' (to be able to "for each" in reverse direction). And
' as the Dictionary type doesn't even support an insert method, we
' have to put it in a collection first.
' Rage, insanity and mayhem!!!
Dim result As New Dictionary(Of TKey, TVal)
Dim col As New Collection(Of KeyValuePair(Of TKey, TVal))
For Each x As KeyValuePair(Of TKey, TVal) In dict
col.Insert(0, x)
Next
For Each x As KeyValuePair(Of TKey, TVal) In col
result.Add(x.Key, x.Value)
Next
Return result
End Function