我正在尝试将 F# 集成为脚本语言,但FsiEvaluationSession.AddBoundVariable
方法有问题。问题是这个方法创建了对象实际类型的变量,但我需要创建它实现的接口变量。我找不到AddBoundVariable<T>(string, T)
或任何其他允许这样做的重载。
// located in common assembly
type IFoo =
abstract Foo : unit -> unit
type FooImpl() =
interface IFoo with
member _.Foo () = ()
// located in host
session.AddBoundVariable ("foo", Foo())
session.EvalInteraction "foo.Foo()" // throws, `FooImpl` type doesn't have `Foo` method
session.EvalInteraction """
let foo : IFoo = foo
foo.Foo()
""" // throws, `IFoo` not found
问题是:如何创建我想要的类型变量?