I have two Classes (i.e. Customer, and Employee) and a generic repository GenericRepository<T> where T : class.
Is is possible to instantiate a new GenericRepository instance while assigning the value of T from a string?
Like this:
string x = "Customer";
var repository = new GenericRepository<x>();
(thus creating a repository instance of type GenericRepository<Customer>)
Yes, but it’s very awkward.
In linqpad,
instance.Dump();:Edit
You could assign the
CreateInstanceresult to a dynamic, and not have to invoke methods through reflection.