In Java I can specify generic with wildcard "?". It is possible to create a map like this one:
Map<String, ?>
.
I'm working with C# and I need a Dictionary<String, SomeInterface<?>>
(where ? can be int, double, any type). Is this possible in C#?
EDIT:
Example:
interface ISomeInterface<out T>{
T Method();
void methodII();
}
class ObjectI : ISomeInterface<int>{
...
}
class ObjectII : ISomeInterface<double>{
...
}
class ObjectIII : ISomeInterface<string>{
....
}
I was trying to map this objects into Dictionary like:
Dictionary<String, ISomeInterface<?>> _objs = new Dictionary<String, ISomeInterface<?>();
_objs.Add("Object1", new ObjectI());
_objs.Add("Object2", new ObjectII());
_objs.Add("Object3", new ObjectII());
foreach(var keyVal in _objs){
Console.WriteLine(keyVal.Method());
}
Objects that implement ISomeInterface are loaded in runtime using Assembly and Activator.createInstance. In the moment of creation I don't if objects implements ISomeInterface<int>
or ISomeInterface<double>
.
Any help is very much appreciated.