gpt4 book ai didi

c# - 如何在 C# 中创建一个包以在 IronPython 中使用

转载 作者:行者123 更新时间:2023-11-30 16:34:41 24 4
gpt4 key购买 nike

我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com