I'm trying to use a .Net library with asynchronous callbacks generated by a number of instances of the API class, and once in my event handler I need to find which instance this particular event came from, as well as all my own information about its context.
The first part is easy as the callback's first argument will be the very object that's sending the notification, and just needs casting. But now I'm stuck looking for a way to associate it with my own data, as that object has very few public properties to identify an instance with.
At the moment, I declared...
Dictionary<TheDotNetClass,MyClass>
..and it works seemingly OK, but my suspicion is that it's simply using the generic Object.getHashCode/compare and it's probably far from safe, might change over time, would lead to way too much collision, etc.
Yet I cannot think of any alternative that would help me connect the generic object I'm getting with all the metadata that I have associated with that API instance on my side.
Am I overlooking something? Is what I'm doing safe enough to scale? Thanks!