相关疑难解决方法(0)

如何从C#调用F#类型扩展(静态成员函数)

FSharp代码结构如下(我不控制源代码).

namespace FS

[<AbstractClass; Sealed>]
type TestType() = 
    static member IrrelevantFunction() = 
        0

[<AutoOpen>]
module Extensions = 
    type TestType with
        //How do we call this from C#
        static member NeedToCallThis() = 
            0

module Caller = 
    let CallIt() = 
        //F# can call it
        TestType.NeedToCallThis()
Run Code Online (Sandbox Code Playgroud)

C#调用代码如下

public void Caller()
{
    TestType.IrrelevantFunction();

    //We want to call this
    //TestType.NeedToCallThis();

    //Metadata:

    //namespace FS
    //{
    //    [Microsoft.FSharp.Core.AutoOpenAttribute]
    //    [Microsoft.FSharp.Core.CompilationMappingAttribute]
    //    public static class Extensions
    //    {
    //        public static int TestType.NeedToCallThis.Static();
    //    }
    //}

    //None of …
Run Code Online (Sandbox Code Playgroud)

c# f#

5
推荐指数
1
解决办法
245
查看次数

标签 统计

c# ×1

f# ×1