c# - 在 F# 中使用程序集属性

标签 c# f# ironpython

我正在尝试将以下构造 IronPython 模块的 C# 示例转换为 F#。

using System;
using IronPython.Runtime;

[assembly: PythonModule("my_module", typeof(MyModule))]

public static class MyModule {
    public static void hello_world() {
        Console.WriteLine("hello world");
    }
}

使用 PythonModule 允许 from my_module import *,等等。

我无法弄清楚如何在 F# 中应用 PythonModule 属性。 F# 文档只讨论与模块相关的程序集属性,并附在 do() 上。我不清楚如何定义被解释为 python 模块的静态类,但我不是 C#/F#/IronPython 专家。

最佳答案

我手头没有所有的东西来查看这是否有效,但我会尝试

open System
open IronPython.Runtime

type MyModule = 
    static member hello_world() =
        Console.WriteLine("hello world")

module DummyModuleOnWhichToAttachAssemblyAttribute =
    [<assembly: PythonModule("my_module", typeof<MyModule>)>] 
    do ()

初学者。

关于c# - 在 F# 中使用程序集属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2269625/

相关文章:

c# - 输出不是在同一数组中交换元素的预期输出

javascript - 引导模式+ajax+jquery+验证+.net core 2.0

f# - f# 中的线程参数

f# - fslex - 如何在两个 token 集之间切换?

ironpython - 如何将 IronPython 作为脚本运行

c# - 文件下载后更新页面

c# - 使用StructureMap注入(inject)相应的实现

f# - 如何在 F# 列表和 F# 元组之间进行转换?

wpf - 来自 WPF 的 IronPython 中的 NLTK

ironpython - 从 Tibco Spotfire DXP 文件导出 IronPython 脚本