下面的代码抛出一个“MissingMemberException”
ScriptEngine engine = Python.CreateEngine();
ScriptRuntime runtime = engine.Runtime;
ScriptScope scope = runtime.CreateScope();
string code = "emp.Name==\"Bernie\"";
ScriptSource source =
engine.CreateScriptSourceFromString(code, SourceCodeKind.Expression);
var emp = new {Name = "Bernie"};
scope.SetVariable("emp", emp);
var res = (double)source.Execute(scope);
如果我声明一个名为“Employee”的类型并给它一个成员“Name”,然后改用它:
var emp = new Employee {Name = "Bernie"}
它按预期工作。有谁知道为什么它不适用于匿名类型并且有解决方法吗?