IronPython的脚本执行功能
— 很好的与.NET和Com互操作;
— 可以生成静态的DLL到文件中,创建的文件包含PDB,因此你可以做断点、察看变量,晕死,强;
— 使用.NET可以非常方便的使用他的引擎,网上的很多资料都旧了些 ,下面的演示创建的代码与自己的程序产生了交互。
using System;
using IronPython.Hosting;

namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
A a = new A();
string code = @"A.Amount = 3";

PythonEngine engine = new PythonEngine();
EngineModule dbafModule = engine.CreateModule("DBAF", true);
dbafModule.Globals.Add("A", a);
engine.Execute(code, dbafModule);

Console.WriteLine(a.Amount);
Console.ReadLine();
}
}

public class A {

private int _amount;

public int Amount {
get { return _amount; }
set { _amount = value; }
}
}
}
— 可以生成静态的DLL到文件中,创建的文件包含PDB,因此你可以做断点、察看变量,晕死,强;
— 使用.NET可以非常方便的使用他的引擎,网上的很多资料都旧了些 ,下面的演示创建的代码与自己的程序产生了交互。
using System;
using IronPython.Hosting;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
A a = new A();
string code = @"A.Amount = 3";
PythonEngine engine = new PythonEngine();
EngineModule dbafModule = engine.CreateModule("DBAF", true);
dbafModule.Globals.Add("A", a);
engine.Execute(code, dbafModule);
Console.WriteLine(a.Amount);
Console.ReadLine();
}
}
public class A {
private int _amount;
public int Amount {
get { return _amount; }
set { _amount = value; }
}
}
}

浙公网安备 33010602011771号