如何将F#函数传递给C#构造函数?
我有以下用F#编写的ViewMode:
type ViewModel(submitFn:Try.SubmitFn) as x =
...
我正在尝试从C#实例化这个视图模型:
var cs_submit = FSharpFunc<ValidatedForm, FSharpResult<ProfileRequest,ValidatedForm>>.ToConverter(Try.submit);
DataContext = new ViewModel(cs_submit);
错误
这是我收到的错误:
> cannot convert from 'method group' to
FSharpFunc<ValidatedForm, FSharpResult<ProfileRequest,ValidatedForm>>
附录
我试图传递给C#代码的实际F#函数如下:
module Try
...
type SubmitFn = ValidatedForm -> Result<Profile, ValidatedForm>
let submit : SubmitFn =
fun registration -> Error registration
答案 0 :(得分:1)
我使用了 FromConverter 而不是 ToConverter :
var cs_submit = FSharpFunc<ValidatedForm, FSharpResult<ProfileRequest,ValidatedForm>>.FromConverter (Try.submit);
DataContext = new ViewModel(cs_submit);