title: Enforcing required function call
body: <p>I have a "Status" class in C#, used like this:</p>
  
  <pre><code>Status MyFunction()
  {
     if(...) // something bad
       return new Status(false, "Something went wrong")
     else
       return new Status(true, "OK");
  }
  </code></pre>
  
  <p>You get the idea.
  All callers of MyFunction <em>should</em> check the returned Status:</p>
  
  <pre><code>Status myStatus = MyFunction();
  if ( ! myStatus.IsOK() )
     // handle it, show a message,...
  </code></pre>
  
  <p>Lazy callers however can ignore the Status.</p>
  
  <pre><code>MyFunction(); // call function and ignore returned Status
  </code></pre>
  
  <p>or </p>
  
  <pre><code>{
    Status myStatus = MyFunction(); 
  } // lose all references to myStatus, without calling IsOK() on it
  </code></pre>
  
  <p>Is it possible to make this impossible? e.g. an throw exception</p>
  
  <p><strong>In general</strong>: is it possible to write a C# class on which you <em>have</em> to call a certain function?</p>
  
  <p>In the C++ version of the Status class, I can write a test on some private bool bIsChecked in the <em>destructor</em> and ring some bells when someone doesn't check this instance.</p>
  
  <p>What is the equivalent option in C#?
  I read somewhere that "You don't want a destructor in your C# class"</p>
  
  <p>Is the Dispose method of the IDisposable interface an option?</p>
  
  <p>In this case there are no unmanaged resources to free.
  Additionally, it is not determined <em>when</em> the GC will dispose the object.
  When it eventually gets disposed, is it still possible to know where and when you ignored that specific Status instance?
  The "using" keyword does help, but again, it is not <em>required</em> for lazy callers.</p>