2016-08-28 37 views
0

我有一個字符串數組是這樣的:得到構造場反射在C#

namespace DynamicCore 
{ 
    public class DynamicCode 
    { 
     public string ProcessName { get; set; } 
     public DynamicCode() 
     { 
      List<Variable> variableList = new List<Variable>(); 
      Variable Variable = new Variable(); 

      Variable.ID = "Variable_26545789"; 
      Variable.Name = "var1"; 
      variableList_Process_1.Add(Variable); 

      Variable = new Variable(); 

      Variable.ID = "Variable_vdvd3679"; 
      Variable.Name = "var2";  

      variableList_Process_1.Add(Variable); 
     } 
    } 
} 

我把它用CompileAssemblyFromSource像這樣(GetCode獲取字符串數組)和存儲類內存編譯

CompilerResults results = provider.CompileAssemblyFromSource(parameters, GetCode()); 

我需要得到variableList並在列表框中顯示Variable.Name項。我測試了GetFieldsGetProperty,但沒有一個不能正常工作。

如果有人能夠解釋這個問題的解決方案,這將是非常有益的。

回答

5

我需要獲取variableList並顯示列表框中的Variable.Name項目。我測試了GetFields和GetProperty,但沒有一個不能正常工作。

兩個variableListVariable當地變量。他們不要住在DynamicCode()構造函數的範圍之外。

將它們聲明爲DynamicCode類中的字段或屬性。

+0

我試圖獲得variableList並忘記它的範圍。謝謝。 –