I'm looking to convert the string name of a class to a class, then pass that class name to a method which accepts <T>
:
var objectList = _reader.GetObjects<MyClassName>();
and the method I'm calling is:
public List<T> GetObjects<T>() where T:new() {
}
Do you know how this can be done? I've tried:
var type = Type.GetType(MyClassName);
var yourObject = Activator.CreateInstance(type);
var objectList = _reader.GetObjects<yourObject>();
but that doesn't work, I get the error message 'yourObject is a variable but is used like a type'
It does work if I use an actual class name.
Any ideas?