Is there any way to call method by name and specify arguments without using dynamic? (C#)
UPDATE:
`
public class Program
{
public static void Main(string[] args)
{
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
engine.ExecuteFile("script.py", scope);
dynamic calculator = scope.GetVariable("Calculator");
dynamic calculatorInstance = engine.Operations.CreateInstance(calculator);
dynamic result = engine.Operations.InvokeMember(calculatorInstance, "sample");
Console.ReadKey();
}
}
`
class Calculator:
def sample(self):
return 'test'
That works great
You can use the
ObjectOperationsclass to perform dynamic operations, and you can get an instance of it from aScriptEngineinstance: