title: How to return specific set of data from a class
body: <p>I have a similar structure to the one below</p>
  
  <p><strong>Base class</strong></p>
  
  <pre><code>public class BaseClass
  {
      public string Name { get; set; }
      public string Address { get; set; }
      public int Age { get; set; }
      public Guid Guid { get; set; }
      public string Hometown { get; set; }
  }
  </code></pre>
  
  <p><strong>Derived Class</strong></p>
  
  <pre><code>public class DerivedClass : BaseClass
  {
      public List&lt;DerivedClassDataItem&gt; Data { get; set; }
  }
  </code></pre>
  
  <p><strong>Data class</strong></p>
  
  <pre><code>public class DerivedClassDataItem
  {
      public string Datum1 { get; set; }
      public string Datum2 { get; set; }
      public string Datum3 { get; set; }
      public string Datum4 { get; set; }
      public int Datum5 { get; set; }
      public DateTime Datum6 { get; set; }
  }
  </code></pre>
  
  <p>What is the best practice to return specific set of info from the <code>DerivedClass</code>?<br>
  a potential set could be:
  <code>Name</code>, <code>Address</code>, <code>Guid</code> and then a <code>Data</code> list that only contains <code>Datum1</code> and <code>Datum4</code></p>
  
  <p>I could see <code>anonymousTypes</code>, <code>Tuples</code> or another set of <code>class(es)</code>, all to be valid approaches.  </p>
  
  <p>My concern about creating new set of classs for the set returned is that the class(s) structure will be similar to the structure of the three mentioned above except it will have fewer selected members, which to me, does not sound ideal. (duplicate code and structure)</p>
  
  <p>Using <code>anonymousTypes</code> was my initial solution to tackle this, something like</p>
  
  <pre><code>List&lt;DerivedClass&gt; list = new List&lt;DerivedClass&gt;();
  
  var mySet = list.Select(d =&gt; new
  {
      Name = d.Name,
      Address = d.Address,
      .
      .
      .
      .
      .
      Data = d.Data.Select(item =&gt; new
      {
          Datum1 = item.Datum1,
          Datum4 = item.Datum4
      })
  });
  </code></pre>
  
  <p>but again, that was a headache for us to track through <code>httpResponse</code> and through out API calls.</p>
  
  <p>Should I go with <code>Tuple</code>? </p>
  
  <p>Any insights as to what is the best practice for doing this?</p>
  
  <p><strong>Edit</strong>
  I am using this set of data to be a response returned by a <code>API/GET</code> call. I will send the set back using <code>HttpRespose</code> and then the framework will transform that into <code>json</code></p>
  
  <p>this is an actual method we have now</p>
  
  <pre><code>private void populateReturnFile()
  {
      var returnFileAnonymous = new
      {
          Vendor = this.Vendor,
          OrganizationName = this.OrganizationName,
          User = this.User,
          Platform = this.Platform,
          DictionaryType = this.DictionaryType,
          UseCaseId = this.UseCaseId,
          Data = this.Data.Select(d =&gt; new
              {
                  MigrationTermId = d.MigrationTermId,
                  ImoLexicalCode = d.ImoLexicalCode
              })
      };
  
      this.returnFile = returnFileAnonymous;
  }
  </code></pre>
  
  <p>Then my <code>GET</code> will return the <code>retunFile</code> (this is a very simple method, i have remove irrelevant code)</p>
  
  <pre><code>[HttpGet]
  public HttpResponseMessage Get(Guid migrationFileId)
  {
      ProblemList problemList = ProblemList.GetProblemList(migrationFileId);
  
      return Request.CreateResponse(HttpStatusCode.OK, problemList.ReturnFile, new JsonMediaTypeFormatter());
  }
  </code></pre>