【发布时间】:2016-02-02 21:13:29
【问题描述】:
我刚刚编写了一个 C# 可以看到但调用它(即使使用有效参数)在运行时抛出的简单方法。
运行时失败的例子:
F#:
namespace Library1
type Class1() =
member __.Foo = "F#"
module MyModule =
// fails at run-time
let inline fOnly (x:^a) : string = (^a:(member Foo: _) x)
// works from C# and F# so I know it's not a problem with my stp
let testFOnly () = fOnly (Class1())
C# 消费者:
namespace ConsoleApplication1
{
class Program
{
var class1 = new Library1.Class1();
// NotSupportedException
var result = Library1.MyModule.fOnly(class1);
Console.ReadLine();
}
}
为什么会编译,然后在运行时失败?我是不是做错了什么,或者我应该假设任何从 C# 调用 stp 方法的尝试总是会失败?那我应该attempt to hide them from C#吗?
【问题讨论】:
标签: c# .net f# inline static-typing