I have a property that returns an interface. During debugging, I can break what was returned, and although it is an interface, Visual Studio is smart enough to know the derived type that it actually is. I guess it uses reflection or something else. I'm not sure. My question is: can I have the same information available to me at runtime so that I can create a variable of the appropriate type and strip the interface? Here is what I am saying:
IPreDisplay preDisplay = cb.PreDisplay;
If preDisplay is RedPreDisplay, I would like to be able to code
RedPreDisplay tmp = preDisplay as RedPreDisplay;
Or, if preDisplay was GreenPreDisplay ...
GreenPreDisplay tmp = preDisplay as GreenPreDisplay;
etc ... I would like to avoid the messy switch statement if possible, and if I could use generics, which would be great.
- , , .