简体   繁体   English

在F#中嵌入互操作类型

[英]Embed Interop Types in F#

Can we embed interop type in F# ? 我们可以在F#中嵌入interop类型吗?

First I dont see the option to do so in the references. 首先,我没有在参考文献中看到这样做的选项。

Second, if I embed the type in C#, it tells me to reference the interface and not the concrete class: 其次,如果我在C#中嵌入类型,它告诉我引用接口而不是具体类:

//DBEngine is the interface DBEngineClass is the concrete class

//if I dont embed the interop

//Valid
var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngineClass();
//Valid
var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine();


//if I do embed the interop
//Invalid
var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngineClass();
//Valid
var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine();

However, F# always wants to have a reference to the concrete class. 但是,F#总是希望引用具体类。 Is there a way around this ? 有没有解决的办法 ?

Tao Liu talks about some additional work you have to do from F# to discover the correct class to instanciate here . 刘涛谈到你要从F#做一些额外的工作,以发现正确的课程,以便在这里实现 To my knowledge, there is no way to embed the interop types. 据我所知,没有办法嵌入互操作类型。 I would be happy to be proven wrong. 我很高兴被证明是错的。 :) :)

Maybe I don't understand your question, but this works fine, referencing v14.0: 也许我不明白你的问题,但这很好用,参考v14.0:

open Microsoft.Office.Interop.Access.Dao
let dbe = DBEngineClass() :> DBEngine

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM