title: C# 8 nullables and Result container
body: <p>I have a <code>IResult&lt;T&gt;</code> container that I use to handle errors. It looks like this:</p>
  
  <pre><code>public interface IResult&lt;out T&gt;
  {
      ResultOutcome Outcome { get; }   //enum: {Failure, Uncertain, Success}
      string Description { get; }      //string describing the error, in case of !Success
      bool IsSuccess();                //Outcome == Success
      T Data { get; }                  //If success, it contains the data passed on, otherwise NULL
  }
  </code></pre>
  
  <p>And you'd use it like this:</p>
  
  <pre><code>IResult&lt;int&gt; GetSomething()
  {
      try{
          int result = //things that might throw...
          return Result&lt;int&gt;.Success(result);  
      } 
      catch(Exception e) 
      {
          return Result&lt;int&gt;.Failure($"Something went wrong: {e.Message}");
      }
  }
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>var result = GetSomething();
  if (!result.IsSuccess()) return result; //&lt;- error passed on.
  
  int resultData = result.Data; //&lt;- no errors, so there is something in here.
  
  </code></pre>
  
  <hr>
  
  <p>Until now, all good. When I introduce the nullable types, though, I have a problem:</p>
  
  <pre><code>public interface IResult&lt;out T&gt; where T : class // unfortunately this is necessary
  {
      ...
      T? Data { get; }                  //If success, it contains the data passed on, otherwise NULL
  }
  </code></pre>
  
  <pre><code>var result = GetSomething();
  if (!result.IsSuccess()) return result; //&lt;- error passed on.
  
  int resultData = result.Data; //&lt;- WARNING!!! POSSIBLE DEREFERENCE OF NULL
  
  </code></pre>
  
  <hr>
  
  <p><strong>Now the question</strong>: I am sure that <code>result.Data</code> contains something, as it passed the <code>IsSuccess()</code> step. How can I reassure the compiler about it? Is there a way or C#8 nullable concept is just not compatible with this?<br>
  Are there other ways to handle results in a similar fashion? (passing on containers instead of exceptions).</p>
  
  <p><em>P.s. 1</em><br>
  Please, don't suggest to use <code>result.Data!;</code>. </p>
  
  <p><em>P.s. 2</em><br>
  This code is already used on a thousand of lines or more, so if the change can be on the interface, rather than on the usages, it would be way better.</p>