在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获得字符串数组)并将类存储在Memory:

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

我需要得到variableList并在列表框中显示Variable.Name项。我测试了GetFieldsGetProperty,但没有一个不能正常工作。

如果有人能解释一下这个问题的解决方法,那就太有帮助了。

我需要得到变量列表和显示变量。在列表框中命名项目。我测试了GetFields和GetProperty,但没有一个不能正常工作。

variableListVariable都是本地变量。它们不在DynamicCode()构造函数的作用域之外。

将它们声明为DynamicCode类中的字段或属性

最新更新