title: Populate an Enum array via reflection
body: <p>I have a method that reads some XML and populates an object. This is done via reflection based on the element names in the XML mathing the property names on the object. This works for basic object types but i am struggling with enum arrays.</p>
  
  <p>So I have a PropertyInfo object (lets call it property) for my enum array property and I have a string value (lets call it value) containing comma separated numbers representing the enum values (e.g. "1,3,5").</p>
  
  <p>I have tried:</p>
  
  <p><code>property.SetValue(this, value.Split(',').Select(i =&gt; int.Parse(i)).ToArray(), null);</code></p>
  
  <p>and</p>
  
  <p><code>property.SetValue(this, value.Split(',').Select(i =&gt; Enum.ToObject(property.PropertyType.GetElementType(), int.Parse(i))).ToArray(), null);</code></p>
  
  <p>But no joy. In the first code example the result of the Select.ToArray is an int[] which then throws a parse error. Similar case with the second but the Select.ToArray returns an object[] and again throws a parse error.</p>
  
  <p>I want to write this as if the enum type is unknown. </p>
  
  <p>Any ideas?</p>