所以我有一个方法可以像这样创建一个新对象:
public class Objects<TObject>
{
public NodeReference<TObject> CreateObject<TObject>(TObject objectType)
where TObject: class, new()
{
NodeReference<TObject> nodeReference = 0;
return nodeReference;
}
}
现在我有其他对象类来定义其他对象类型,例如 Car。
public class Car
{
public int NumberOfDoors {get; set;}
public int NumberOfWheels {get; set;}
}
现在假设我得到了一个字符串,我将如何在运行时将此字符串转换为它的类型?
var carObjectReference = CreateObject<//string converted to identify object car dynamically>(//new Car { });