I’m wondering if it’s possible to use reflection to locate an object at runtime? This is more of an experiment than a practical requirement.
I’ve used the .GetType() method on an object instance to do various things to the object, but my question is: what if I know an object of a certain type exists at runtime, but I can’t refer to it by name.
As a more concrete example, suppose I have a WinForms app that loads a DLL – how might that DLL independently locate a reference to the form object in order to interact with the form, or call a public method?
Is this even possible?
No, basically.
You could have some sort of horrible global map from type to “the instance of the type I’m interested in” but otherwise, no.
Basically, the WinForms app should pass a reference to the form into the DLL somehow.