title: Elegant way to validate values
body: <p>I have a class with many fields which represents different physical values.</p>
  
  <pre><code>class Tunnel
  {
      private double _length;
      private double _crossSectionArea;
      private double _airDensity;
      //...
  </code></pre>
  
  <p>Each field is exposed using read/write property. I need to check on setter that the value is correct and generate exception otherwise. All validations are similar:</p>
  
  <pre><code>    public double Length
      {
          get { return _length; }
          set
          {
              if (value &lt;= 0) throw new ArgumentOutOfRangeException("value",
                      "Length must be positive value.");
              _length = value;
          }
      }
  
      public double CrossSectionArea
      {
          get { return _crossSectionArea; }
          set
          {
              if (value &lt;= 0) throw new ArgumentOutOfRangeException("value",
                      "Cross-section area must be positive value.");
              _crossSectionArea = value;
          }
      }
  
      public double AirDensity
      {
          get { return _airDensity; }
          set
          {
              if (value &lt; 0) throw new ArgumentOutOfRangeException("value",
                      "Air density can't be negative value.");
              _airDensity = value;
          }
      }
      //...
  </code></pre>
  
  <p>Is there any elegant and flexible way to accomplish such validation?</p>