Is it possible to return an object of type
IModel< T >
without knowing the type parameter?
the objects are stored in a dictionary, with Type as the key and an object with IModel
(base interface to IModel<T>
) implemented as a value.
The interface IModel<T>
inherits from IModel
, but to do the full action I need an object of IModel<T>
. T
needs to have the interface IFactoryItem
.
but first the code:
public IModel<T> GetModel<T>() where T : IFactoryItem
{
Type tmpType = typeof(T);
if (!_allModelsByType.ContainsKey(tmpType))
return null;
return (IModel<T>)_allModelsByType[tmpType];
}
i thought of a solution like
public IModel GetModel(Type t) and a wrapper to cast it to the right type.
I hope that i am not totally wrong. this is my first question.