I want to write in Delphi (2009 – so I have generic dictionary class) something similar to that C# code:
Dictionary<Type, Object> d = new Dictionary<Type, Object>();
d.Add(typeof(ISomeInterface), new SomeImplementation());
object myObject = d[typeof(ISomeInterface)];
Any ideas?
Thanks in advance,
Hristo
For interfaces, you’ll want to use a PTypeInfo pointer, which is returned by the compiler magic function TypeInfo. PTypeInfo is declared in the TypInfo unit.
Of course, if this was classes instead of interfaces, you could just use a TClass reference.