作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 IronPython 邮件列表上看到了描述如何用 C# 编写扩展模块的文档。我已经能够按照文档进行操作并且工作正常。但是,有谁知道如何在 C# 中生成分层扩展包?例如你应该为一个模块做这样的事情:
[assembly: PythonModule("my_module", typeof(test.MyModule))]
namespace test
{
public static class MyModule
{
public static void hello_world()
{
Console.WriteLine("hello world");
}
}
但是您如何在 my_module 下创建一个名为 testme 的模块,您将像这样导入它:
from my_module import testme
一个简短的例子或向正确方向轻轻插入会很棒!
最佳答案
我所做的是像往常一样创建我的 C# 库,例如
namespace foo.bar{
public class Meh{
public void CanDoSomething(){
//does something
}
}
}
然后去
import clr
clr.AddReference("My.DLL") # You may want to change it to AddReferenceByPath or depending on your needs
from foo.bar import Meh
mehvar = Meh()
mehvar.CanDoSomething()
您可以在 http://www.theautomatedtester.co.uk/seleniumtraining/selenium_two_ironpython.htm 看到一些对我有用的测试代码
关于c# - 如何在 C# 中创建一个包以在 IronPython 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2365661/
我是一名优秀的程序员,十分优秀!