Pergunta

I am trying to write a module in F#, making it easier working with Excel, by extracting rows, columns, etc. along with type casting and so on. One of the first things I wanted to do, was to extend various classes/types to implement the IDisposable interface. I tried to write something like the following

type Excel.ApplicationClass with
    interface IDisposable with
        member this.Dispose() =
            this.excel.Quit()
            Marshal.ReleaseComObject(this.excel) |> ignore

What I wasn't aware of, was that I would get the following error "All implemented interfaces should be declared on the initial declaration of the type".

My question is the following: Since I am not allow to extend a type with an interface - what else could I do?

Foi útil?

Solução

If you inherit from the base class it can work, like this

type myAppClass() =
    inherit Excel.ApplicationClass() //may not be correct signature - you need to match the base constructor
    interface IDisposable with
        member this.Dispose() =
            //function body
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top