2017-03-04 16 views
0

我有一組代碼,它接受一個包含我需要引用的類的確切名稱的值(字符串)。要引用的類位於單獨的DLL文件中(我已經爲該DLL放置了using lib_vxmanager;)。我只是需要得到的字符串,可以用來做這樣的事情正確的類型:C#/ .NET將字符串轉換爲引用DLL類的可用類型

Classname class = new Classname(); 

代碼示例:

public void Classreference(string reference_name) 
{ 
    string Classname = reference_name.Split('{','}')[0]; //This is the classname 
    //Convert name to type here 
} 

回答

1

您需要使用Activator

var obj = Activator.CreateInstance("Your assembly name", "Your class name"); 
0

您可以嘗試Assembly.CreateInstanceActivator.CreateInstance

相關問題