That happens because your method tries to assign an object of type TClass
or HClass
to an object of type T
. Since there are no constraints for T
, T
can be anything and, you cannot assign TClass
or HClass
to anything...
Maybe, you intended to write something like:
T CreateInst<T>(object param1) where T : class
{
T _requestType = null;
if(typeof(T) == typeof(TClass))
{
_requestType = _factory.CreateA(param1) as T ;
}
else if(typeof(T) == typeof(HClass))
{
_requestType = _factory.CreateB(param1) as T ;
}
return _requestType;
}