title: Fluent Validation - How to ensure that a collection Count greater than zero when not null, but can be null
body: <p>I'm struggling to figure out how to define a rule that allows a collection property to be null, but not empty. Providing null for the collection property being a valid use case, but when the collection is provided, the collection needs to have at least one entry. Hence:</p>
  
  <pre><code>// Valid
  {
      "codes": null
  }
  
  // Invalid
  {
      "codes": []
  }
  
  // Valid
  {
      "codes": ["Pass"]
  }
  </code></pre>
  
  <p>I've been playing around and can't seem to find anything that works:</p>
  
  <pre><code>public class UpdateCodesRequest
  {
      public IEnumerable&lt;string&gt; Codes { get; set; } 
  }
  
  public class UpdateCodesRequestValidator : AbstractValidator&lt;UpdateCodesRequest&gt;
  {
      public UpdateCodesRequestValidator()
      {
          // none of these will work if Codes is null
          RuleFor(x =&gt; x.Codes.Count()).GreaterThan(0).When(x =&gt; x != null);
          RuleFor(x =&gt; x.Codes).Must(x =&gt; x.Any()).When(x =&gt; x != null);
          RuleFor(x =&gt; x.Codes).Must(x =&gt; x != null &amp;&amp; x.Any()).When(x =&gt; x != null);
      }
  }
  </code></pre>