I want to implement a dictionary that creates its own elements on the fly only when they are accessed (not in advance). To do that I would like to use a getter method, but I simply don’t find any information how to declare a getter in the context of dictionary elements.
I do understand how to add a getter to the whole dictionary (which must return a dictionary when called), but what I want to do is implement a getter that is called when a single element in the dictionary is accessed so I can create that element on the fly. That getter must receive the key that is used for the request as a parameter and it must return the corresponding value.
I do not find any syntax for that task in the docs.
You just need to reimplement the indexer on
Dictionary<,>If you need a more sophisticated value instantiation, you can use an activator function
Usage: