Ordered Dictionary?

That should be doable also. Add another class property:

Private Property mKeyType as Xojo.Introspection.TypeInfo

And a new constructor:

Sub Constructor(keyType as Xojo.Introspection.TypeInfo)
  self.mKeyType = keyType
End Sub

At the beginning of method Value insert:

Sub Value(key as Variant, Assigns data as Variant)
  dim keyType as Xojo.Introspection.TypeInfo = Xojo.Introspection.GetType(key)
  if not (self.mKeyType Is nil) and (keyType.FullName <> self.mKeyType.FullName) then
    Raise new UnsupportedFormatException
  end if

  // code as shown in my first post goes here
End Sub

Then you can instantiate a new OrderedDictionary like this:

dim dict as new OrderedDictionary(GetTypeInfo(Class1))

Now you can only add keys of type Class1. Any other type will throw an UnsupportedFormatException.

To get the list of keys as an array of type Class1 is a bit ugly. You could write a conversion method that takes/extends an array of Variant and returns an array of Class1.

1 Like