locked
Contract.Ensures causes CA2000 to reappear RRS feed

  • Question

  • Hi,

    I have a function in which I return a disposable type. To correctly handle the CA2000 case, I implemented this pattern

    Dim retVal as IDisposable
    dim tempObj as IDisposable
    Try
      tempObj = new DisposableObj()
      <DoStuff>
      retVal=tempObj
      tempObj=Nothing
    Finally
      If tempObj IsNot Nothing then tempObj.Dispose()
    End Try
    
    Return retVal

    Done this way, it works but if I add Contract.Ensures, CA2000 is back

    Contract.Ensures(Contract.Result(Of IDisposable)() IsNot Notring)
    
    Dim retVal as IDisposable
    dim tempObj as IDisposable
    Try
      tempObj = new DisposableObj()
      <DoStuff>
      retVal=tempObj
      tempObj=Nothing
    Finally
      If tempObj IsNot Nothing then tempObj.Dispose()
    End Try
    
    Return retVal


    Since both are CC related, I suppose this is something that could be handled.


    BKQc

    Thursday, November 19, 2015 7:34 PM