这个SO question 提供了在 C# 中创建 python 类的实例的代码。
下面的代码强制提前知道python函数名。但是我需要指定要由字符串执行的类名和函数名。
ScriptEngine engine = Python.CreateEngine();
ScriptSource source = engine.CreateScriptSourceFromFile("Calculator.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope);
dynamic class_object = scope.GetVariable("Calculator");
dynamic class_instance = class_object();
int result = class_instance.add(4, 5); // I need to call the function by a string