Are there any properties of the Let- or Use- Bound in F # object?

Consider the following F # code example:

type mytype() =
   member this.v = new OtherClass()

If OtherClass implements IDisposable, does element binding act like let or use binding? Is there a way to make it act as a binding to use? I have code very similar to this code, and I want to make sure that Dispose is called when the parent object goes out of scope.

A quick scan through Expert F # did not get anything definite, but maybe I was looking for the wrong terms in the book.

+3
source share
1 answer

v ( , OtherClass , - ). , :

let m = new MyType()
use v = m.V // 'use' binding

, , . , - :

type MyType() =
  let v = new OtherClass() 
  member this.V = v

let , v , MyType . v, IDisposable MyType:

type MyType() =
  let v = new OtherClass() 
  member this.V = v
  interface IDisposable with 
    member x.Dispose() = (v :> IDisposable).Dispose()

, , ( use IDisposable F #,
 (: -).))

+6

Source: https://habr.com/ru/post/1781710/


All Articles