Hi,
I have created a c# program, which will call python method and passing .net dynamic object to that python method and I don't know why it is not calling instance member (NOTE: when i override a ToString() method it is calling the corresponding class here Demo class ToString() method)
Kindly help me please.....
My pythonscripts.py has method
def CallInstance(obj):
print obj.objectType
def CallMethod(obj):
print obj.objectType.Test()
My .net code is here
Code:
class SampleScriptLanguage
{
ScriptRuntime _scriptRuntime = Python.CreateRuntime();
ScriptEngine _scriptEngine;
ScriptSource _scriptSource;
ScriptScope _scriptScope;
string scriptToUse;
public SampleScriptLanguage()
{
_scriptEngine = _scriptRuntime.GetEngine("Python");
dynamic _scriptScope = _scriptRuntime.UseFile("PythonScripts.py");
dynamic expandObject1 = new ExpandoObject();
expandObject1.objectType = new Demo();
_scriptScope.CallInstance(expandObject1); // This is working
_scriptScope.CallMethod(expandObject1); // This is not working
}
}
class Demo
{
public string ID
{
get
{
return this.Test();
}
}
public string Test()
{
return "Test Method";
}
public override string ToString()
{
return "To string method";
}
}