2013-11-02 66 views
-3

我有一個由javascript發送的字符串列表。如何將列表字符串轉換爲特定的對象

List<string> options = new List<string>() 
     { 
      {"new MeuObjeto(\"teste 1\", 10, 12, 50, 70, 0, new System.Drawing.Font(\"Arial\", 10, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point), System.Drawing.Color.Black, false)"}, 
      {"new MeuObjeto(\"teste 2\", 10, 14, 50, 70, 0, new System.Drawing.Font(\"Arial\", 14, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point), System.Drawing.Color.Black, false)"}, 
      {"new MeuObjeto(\"teste 3\", 10, 16, 50, 70, 0, new System.Drawing.Font(\"Arial\", 35, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point), System.Drawing.Color.Black, false)"}, 
      {"new MeuObjeto(\"teste 4\", 10, 18, 50, 70, 0, new System.Drawing.Font(\"Arial\", 10, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point), System.Drawing.Color.Black, false)"}, 
      {"new MeuObjeto(\"teste 5\", 10, 20, 50, 70, 0, new System.Drawing.Font(\"Arial\", 9, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point), System.Drawing.Color.Black, false)"}, 
      {"new MeuObjeto(\"teste 6\", 10, 22, 50, 70, 0, new System.Drawing.Font(\"Arial\", 10, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point), System.Drawing.Color.Black, false)"} 
     }; 

如何將此數據轉換爲對象(MeuObjeto)?

回答

2

可以像這樣從字符串編譯和執行C#代碼。你絕對不想這樣做,因爲它會打開服務器中最大的安全漏洞,因爲它會盡職地編譯和執行發送給它的任何東西。

相反,您應該發送數據並編寫代碼以從該數據創建MeuObjeto的實例。

+0

是的,我知道。但我怎麼做,你評論動態編譯? –

相關問題