If you cannot find a replacement, and you do not want to change the type of collection you are using, the simplest way is to create a protected wrapper type around the OrderedDictionary.
It does the same thing you are doing now, but code that does not match the type is much more limited, only in this class. In this class, we can rely on a support dictionary that contains only the TKey and TValue types, because it can only be inserted from our own Add methods. In the rest of the application, you can see this as a type-safe collection.
public class OrderedDictionary<TKey, TValue> : IDictionary<TKey, TValue> { private OrderedDictionary backing = new OrderedDictionary();
source share