I’d like to add some helper functions to the dictionary returned by the ParseJSON function.
Ideally I’d like to define a subclass of dictionary and be able to instantiate this subclass from the dictionary superclass returned by ParseJSON. We can do something similar with a folderitem but I can’t figure out how to do it with a dictionary.
What’s the best practice for this?
I don’t want to use Extension methods since these helpers are for JSON processing and don’t apply to generic dictionaries.
I’ve tried assigning the superclass instance to a variable of my subclass type (Illegal cast exception) and also passing the superclass dictionary instance into the constructor of my subclass. Neither work to create a usable dictionary with the original data. One potential solution seems to be in the Constructor to retain a reference to the superclass dictionary and overload any normal dictionary method I want to use and have them reference my reference to the superclass dictionary. But that’s a lot of extra methods to recreate, essentially unchanged.
How to create a subclass instance from a superclass instance? If we have an Animal superclass why can’t we now extend it with further details into a new instance of Dog subclass? Of course you can’t use a superclass instance as a subclass instance, but it sure seems like you should be able to create a subclass instance from a superclass instance. (Just like we can create a subclass definition from a superclass definition)
Any better ideas for adding methods to a Xojo builtin class?