title: Determine if a Type is a Generic List of Enum Types
body: <p>I have the need to determine if a given type if a generic list of enum types.</p>
  
  <p>I came up with the following code:</p>
  
  <pre><code>void Main()
  {
      TestIfListOfEnum(typeof(int));
      TestIfListOfEnum(typeof(DayOfWeek[]));
      TestIfListOfEnum(typeof(List&lt;int&gt;));
      TestIfListOfEnum(typeof(List&lt;DayOfWeek&gt;));
      TestIfListOfEnum(typeof(List&lt;DayOfWeek&gt;));
      TestIfListOfEnum(typeof(IEnumerable&lt;DayOfWeek&gt;));
  }
  
  void TestIfListOfEnum(Type type)
  {
      Console.WriteLine("Object Type: \"{0}\", List of Enum: {1}", type, IsListOfEnum(type));
  }
  
  bool IsListOfEnum(Type type)
  {
      var itemInfo = type.GetProperty("Item");
      return (itemInfo != null) ? itemInfo.PropertyType.IsEnum : false;
  }
  </code></pre>
  
  <p>Here's the output from the code above:</p>
  
  <pre><code>Object Type: "System.Int32", List of Enum: False
  Object Type: "System.DayOfWeek[]", List of Enum: False
  Object Type: "System.Collections.Generic.List`1[System.Int32]", List of Enum: False
  Object Type: "System.Collections.Generic.List`1[System.DayOfWeek]", List of Enum: True
  Object Type: "System.Collections.Generic.List`1[System.DayOfWeek]", List of Enum: True
  Object Type: "System.Collections.Generic.IEnumerable`1[System.DayOfWeek]", List of Enum: False
  </code></pre>
  
  <p>All of the output is exactly what I want except for the last example. It doesn't detect that <code>typeof(IEnumerable&lt;DayOfWeek&gt;)</code> is a collection of enum types.</p>
  
  <p>Does anyone know how I can detect the enum types in this last example?</p>