我有一个像这样的字符串数组:
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用CompileAssemblyFromSource像这样(GetCode获取字符串数组)并在内存中存储类来编译它:
CompilerResults results = provider.CompileAssemblyFromSource(parameters, GetCode());
Run Code Online (Sandbox Code Playgroud)
我需要在列表框中variableList显示和显示Variable.Name项目.我测试过GetFields,GetProperty但没有一个没有正常工作.
如果有人可以解释这个问题的解决方案将是非常有帮助的.
我需要获取variableList并在列表框中显示Variable.Name项.我测试了GetFields和GetProperty,但没有一个没有正常工作.
这两个variableList和Variable是局部变量.它们不属于DynamicCode()构造函数的范围.
将它们声明为类中的字段或属性DynamicCode.