【发布时间】:2015-04-01 14:00:29
【问题描述】:
我用 F# 编写了一个实现接口的类,以便为我的 F# 程序集构建一个 C# 友好的接口。
我已经将一些属性编写为索引属性。但是,当我尝试使用 C# 中的类型时,我只能在智能感知中获得合成的 get_PropertyName 方法,并且编译器同样会抱怨,以防我想像使用 C# 那样使用索引属性。
参考代码:
type IMyInterfaceType =
abstract MyProperty : MyType1 with get
abstract MyIndexedProperty : MyType2 -> MyType3 with get
abstract MyTwoDimensionalIndexedProperty : (MyType4 * MyType5) -> MyType6 with get
type MyInterfaceType =
new () = { }
interface IMyInterfaceType with
member this.MyProperty with get () = new MyType1 ()
member this.MyIndexedProperty with get parameter = new MyType3 ()
member this.MyTwoDimensionalIndexedProperty with get pair = new MyType6 ()
尝试从 C# 访问此类时,我只获取方法
get_MyIndexedProperty(MyType2 parameter)
get_MyTwoDimensionalIndexedProperty(Tuple<MyType4, MyType5>)
而不是我希望的索引属性。
我做错了什么还是这是一个已知问题?
干杯
--马蒂亚斯。
【问题讨论】:
标签: f#