title: Avoid CS8618 warning when initializing mutable non nullable property with argument validation
body: <p>I have a question regarding <a href="https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types" rel="noreferrer">nullable reference type system</a> available since C# 8.</p>
  <p>Suppose we have a C# domain model class with a mutable reference type property like below:</p>
  <pre><code>public class Person
  {
  
      public string Name { get; set; }
  
      public Person(string name)
      {         
          Name = name;
      }
  }
  </code></pre>
  <p>So far no problem. But consider real world scenario, I often want to check the validity of the property as it's a public mutable property and I have to make sure the model invariant whenever property is changed.</p>
  <pre><code>public class Person
  {
      private string _name;
      public string Name
      {
          get =&gt; _name;
          set =&gt; _name =
              value ?? throw new ArgumentNullException(&quot;Name is required.&quot;);
      }
      public Person(string name)
      {         
          Name = name;
      }
  }
  </code></pre>
  <p>Then compiler generates <code>CS8618</code> warning, basically saying:</p>
  <blockquote>
  <p>Non nullable field _name is not initialized. Consider declare the
  field as nullable type.</p>
  </blockquote>
  <p>So every time I encounter the warning I have to enclose the constructor with the following pragma directive.</p>
  <pre><code>#pragma warning disable CS8618
  public Person(string name)
  {         
      Name = name;
  }
  #pragma warning restore CS8618
  </code></pre>
  <p>But I think it's redundant and tedious to do it always. Am I misusing something or is there better way to write such property without warning?</p>
  <p>Of course I can change the property type to <code>string?</code> as compiler suggests but notionally it's not acceptable as a solution as Person should always have non null name and we want to explicit about such invariant condition in domain class.</p>
  <p>Another solution I considered is to drop the argument validation logic and just relying on the nullable compiler warning, but it's not always possible (I mean often validation other than null check is also required.), it's just warning anyway in regular project settings, so I don't think it's a good solution.</p>