C#代码
public
partial
class
Form1 : Form
{
public static PythonEngine engine;
private static ClrModule clr;
private void InitializePythonEngine()
{
engine = new PythonEngine();
clr = (ClrModule)engine.Import("clr");
engine.Globals.Add("SysPath",
System.Environment.GetFolderPath(System.Environment.SpecialFolder.System)+"/");
}
public Form1()
{
InitializeComponent();
InitializePythonEngine();
}

private void button1_Click(object sender, EventArgs e)
{
scriptEngine.Execute(textBox1.Text);
}
}
编译C#文件为类库
csc /t:library /out:1TestDll.dll *.cs
IronPython中调用动态库中自定义的类
import
clr
import
System

clr.AddReference(
"
System.Windows.Forms
"
)
clr.AddReference(
"
System.Drawing
"
)
from
System.Windows.Forms
import
*
from
System.Drawing
import
*
from
System.IO
import
*
from
System.Reflection
import
*

#
用python也可以实现相同的功能
#
b = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) +"/"
#
dllfilename = b + "TestDll.dll"
#
调用动态库
dllfilename
=
SysPath
+
"
TestDll.dll
"
clr.AddReferenceToFileAndPath(dllfilename)
from
TestDll
import
*

f
=
Form1()
f.ShowDialog()
附录A
csc编译动态库参数说明:
csc /t:library /out:文件名.dll /r:引用文件名(包含路径) /recurse:包含的文件(含路径) *.cs
























编译C#文件为类库
csc /t:library /out:1TestDll.dll *.cs
IronPython中调用动态库中自定义的类





















附录A
csc编译动态库参数说明:
csc /t:library /out:文件名.dll /r:引用文件名(包含路径) /recurse:包含的文件(含路径) *.cs