title: Return Object List of Specific Derived Type
body: <p>I should preface this by saying that this will implemented in Unity, so I may use some functions and class names from there, but here goes:</p>
  
  <p>I have a class for the possible item types in my game that will be stored in a JSON file:</p>
  
  <pre><code>public class Item
  {
      //Properties galore
  }
  
  public class Weapon : Item
  {
      //All my weapon stats
  }
  
  public class Projectile : Weapon
  {
      //All my projectile weapon stats
  }
  </code></pre>
  
  <p>So now I can pull in a bunch of stats and weapons. My player's current inventory, for example, is stored in a list:</p>
  
  <pre><code>List&lt;Item&gt; playerInventory = new List&lt;Item&gt;();
  
  //And then I go on and add my inventory items from a stored file, etc.
  </code></pre>
  
  <p>So poof, now my player has an inventory. Yay. Unfortunately, I'm struggling to figure out a way to get a list of JUST Weapons, or JUST Projectile Weapons. I could add a "type" parameter to my JSON file that holds the defaults for each weapon, etc., but it seems like C# would have a way to do something clever like</p>
  
  <pre><code>List&lt;Weapon&gt; weaponList = new List&lt;Weapon&gt;();
  
  foreach(Item&lt;Weapon&gt; i in playerInventory)
  {
     weaponList.Add(i);
  }
  </code></pre>
  
  <p>I know, I know, this isn't right at all, but hopefully you get my point. It doesn't have be exactly like that of course, but I figured there must be a way to turn a list of Items into a new list of Weapons relatively painlessly.</p>
  
  <p>Thanks for any help you can provide!</p>