title: How to know if a PropertyInfo is a collection
body: <p>Below is some code I use to get the initial state of all public properties in a class for IsDirty checking.</p>
  
  <p>What's the easiest way to see if a property is IEnumerable?</p>
  
  <p>Cheers,<br>
  Berryl</p>
  
  <pre><code>  protected virtual Dictionary&lt;string, object&gt; _GetPropertyValues()
      {
          return _getPublicPropertiesWithSetters()
              .ToDictionary(pi =&gt; pi.Name, pi =&gt; pi.GetValue(this, null));
      }
  
      private IEnumerable&lt;PropertyInfo&gt; _getPublicPropertiesWithSetters()
      {
          return GetType().GetProperties().Where(pi =&gt; pi.CanWrite);
      }
  </code></pre>
  
  <h1>UPDATE</h1>
  
  <p>What I wound up doing was adding a few library extensions as follows</p>
  
  <pre><code>    public static bool IsNonStringEnumerable(this PropertyInfo pi) {
          return pi != null &amp;&amp; pi.PropertyType.IsNonStringEnumerable();
      }
  
      public static bool IsNonStringEnumerable(this object instance) {
          return instance != null &amp;&amp; instance.GetType().IsNonStringEnumerable();
      }
  
      public static bool IsNonStringEnumerable(this Type type) {
          if (type == null || type == typeof(string))
              return false;
          return typeof(IEnumerable).IsAssignableFrom(type);
      }
  </code></pre>