I want to be able to get the actual Type of a string value I receive by some means (i.e from database) so I can use that Type in generic method like DoSomething<Type>()
.
In my project, I have classes Plane
, and Car
located in MyCompany.MySolution.Vehicle
namespace like so
- MyCompany.MySolution.Vehicle
|+Interfaces
|-Implementations
|-Car
|-Plane
I receive type of the vehicle as a string. So, I get string "Car" which means, I need to get Type Car
so I can use that type in a generic method to register it like so:
MyFactory.Register<Car>(carId)
So, MyFactory is static class calling Register() method.
Similarly, I receive string "Plane" which means, I need to get Type Plane
so I can use that type in the generic method above to register a Plane.
I tried using something like
MyFactory.Register<Type.GetType("MyCompany.MySolution.Vehicle.Implementations.Car")>(carId)
,but that does not work.
Car
(including the namespace)? i.e.Type.GetType("MyCompany.MySolution.Vehicle.Implementations.Car")
– Fanchon