title: Create a subset of an object based off an array of property names
body: <p>I have a class and an array of property names defined as follows:</p>
  
  <pre><code>public class Dog {
      public string Name { get; set; }
      public string Breed { get; set; }
      public int Age { get; set; }
  }
  
  var desiredProperties = new [] {"Name", "Breed"};
  </code></pre>
  
  <p>I also have a method that returns a list of dog objects:</p>
  
  <pre><code>List&lt;Dog&gt; dogs = GetAllDogs();
  </code></pre>
  
  <p>Is there an way I can return a subset of <code>dogs</code> that only contain the properties defined within the <code>desiredProperties</code> array? Eventually, this resulting list will be serialized to JSON.</p>
  
  <p>I have been struggling with this problem for some time now, considering that the user will be allowed to specify any combination of properties (assuming they are all valid) as the output within the array. Some more examples:</p>
  
  <pre><code>var desiredProperties = new [] {"Name", "Age"};
  // Sample output, when serialized to JSON:
  // [
  //   { Name: "Max", Age: 5 },
  //   { Name: "Spot", Age: 2 }
  // ]
  
  var desiredProperties = new [] {"Breed", "Age"};
  // [
  //   { Breed: "Scottish Terrier", Age: 5 },
  //   { Breed: "Cairn Terrier", Age: 2 }
  // ]
  </code></pre>