【问题标题】:How to convert list string to specific object [closed]如何将列表字符串转换为特定对象[关闭]
【发布时间】:2013-11-02 02:14:08
【问题描述】:

我有一个由 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)?

【问题讨论】:

    标签: c# dynamic compiler-construction eval


    【解决方案1】:

    可以从这样的字符串编译和执行 C# 代码。您绝对不想这样做,因为它会在您的服务器中打开最大的安全漏洞,因为它会尽职尽责地编译和执行发送给它的任何内容。

    相反,您应该只发送数据并编写代码以从该数据创建MeuObjeto 的实例。

    【讨论】:

    • 是的,我知道。但是我该怎么做你评论的动态编译呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    相关资源
    最近更新 更多