title: How can I cast IEnumerable<?> to IEnumerable<string>?
body: <p><strong>This question was completely edited. To see the original one, see the edit history</strong></p>
  
  <hr>
  
  <p>I think I should explain a little bit of my situation and context of the problem.</p>
  
  <p>I'm inspecting a type for a property annotated with a custom attribute. I then get the value of that property, but as an <code>object</code>:</p>
  
  <pre><code>IEnumerable&lt;object&gt; propertiesValues = myType.GetProperties().Where(p =&gt; p.GetCustomAttributes(typeof(MyCustomAttribute)) != null);
  </code></pre>
  
  <p>Once I have these values I want to call my method <code>Map</code> on them, which converts them to a different object depending on their type. This is because my database API requires so.</p>
  
  <pre><code>foreach(object value in propertiesValues)
  {
       object mapped = Map(value);
       // ...
  }
  </code></pre>
  
  <p>I need all <code>IEnumerable&lt;NumberType&gt;</code> values, to be converted to <code>IEnumerable&lt;string&gt;</code>. So my first approach was:</p>
  
  <pre><code>public static object Map(object value)
  {
      if(value is IEnumerable&lt;short&gt; || value is IEnumerable&lt;int&gt; || ....)
           return ((IEnumerable&lt;object&gt;) value).Cast&lt;string&gt;();
  }
  </code></pre>
  
  <p>However, this is throwing a runtime exception, as I cannot cast <code>IEnumerable&lt;int&gt;</code> to <code>IEnumerable&lt;object&gt;</code> for example.</p>