title: Auto-implemented properties with non null guard clause?
body: <p>I do agree with Mark Seeman's notion that <a href="http://blog.ploeh.dk/2011/05/26/CodeSmellAutomaticProperty.aspx">Automatic Properties are somewhat evil</a> as they break encapsulation. However I do like the concise syntax, readability and convenience they bring.</p>
  
  <p>I quote:</p>
  
  <pre><code>public string Name { get; set; }
  </code></pre>
  
  <blockquote>
    <p>The problem with the code snippet isn’t that it contains too much
    ceremony. The problem is that it breaks encapsulation. In fact</p>
    
    <p>“[…] getters and setters do not achieve encapsulation or information
    hiding: they are a language-legitimized way to violate them.”</p>
    
    <p>James O. Coplien &amp; Gertrud Bjørnvig. Lean Architecture. Wiley. 2010. p. 134.</p>
  </blockquote>
  
  <p>Most of the time, adding a non-null guard clause is good enough for a property setter and I would like to know if there is a better way of doing it than one of the below. By better, I mean in a more concise/less repetitive way.</p>
  
  <p>Using Code Contracts:</p>
  
  <pre><code>private string _username;
  public virtual string Username
  {
      get { return _username; }
      set 
      {  
          Contract.Requires(value != null);
          _username = value; 
      }
  }
  </code></pre>
  
  <p>Using vanilla .NET:</p>
  
  <pre><code>private string _username;
  public virtual string Username
  {
      get { return _username; }
      set 
      {
          if (value == null) throw new ArgumentNullException("Username");
          _username = value; 
      }
  }
  </code></pre>