title: How do I get the count from ICollection<T> with an unknown T
body: <p>Here is my code so far:</p>
  
  <pre><code>//TODO: Look for a way of handling ICollection&lt;T&gt;
  
  if (value is ICollection)
  {
      return CreateResult(validationContext, ((ICollection)value).Count);
  }
  
  if (value is IEnumerable)
  {
      var enumerator = ((IEnumerable)value).GetEnumerator();
      try
      {
          var count = 0;
          while (enumerator.MoveNext())
              count++;
          return CreateResult(validationContext, count);
      }
      finally
      {
          if (enumerator is IDisposable)
              ((IDisposable)enumerator).Dispose();
      }
  
  }
  </code></pre>
  
  <p>Is there a good way of getting the <code>Count</code> out of <code>ICollection&lt;T&gt;</code> without resorting to iterating over the collection?</p>