IronPython.dll
----------c#---------
using Microsoft.Scripting;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
public class Student
{
public void xxx(int i,Student s){
Console.WriteLine("xxx "+i+" "+s.Name);
}
public int Age { get; set; }
public string Name { get; set; }
public override string ToString()
{
return string.Format("{0} is {1} years old", this.Name, this.Age);
}
}
void test()
{
try
{
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
Student stu = new Student { Name = "Wilber", Age = 28 };
scope.SetVariable("stuObj", stu);
ScriptSource script = engine.CreateScriptSourceFromFile(@"PrintStuInfo.py");
var result = script.Execute(scope);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.Read();
}
---------------python-------------
PrintStuInfo.py
print "Student name:", stuObj.Name
print "Student age:", stuObj.Age
stuObj.Name="lkjsdl"
print stuObj.ToString()
print "sdlkfj2304"
stuObj.xxx(3,stuObj)