title: Extending classes with additional properties
body: <p>I have an class object from an external library that I want to add some additional properties to.</p>
  
  <p>Let's say the external class is:</p>
  
  <pre><code>public class ExternalClass
  {
      public string EXproperty1 {get;set;}
      public string EXproperty2 {get;set;}
      public string EXproperty3 {get;set;}
  
      public ExternalClass(){}
  }
  </code></pre>
  
  <p>and I have a list of these object which gets populated as</p>
  
  <pre><code>List&lt;ExternalClass&gt; listOfExternalClass=new List&lt;ExternalClass&gt;();
  listOfExternalClass=GetListOfExternalClass();
  </code></pre>
  
  <p>I can extend this class by creating a new class, adding the additional properties and making the external class a property.</p>
  
  <pre><code>public class NewClass
  {
      public ExternalClass ExternalClass {get;set;}
      public string NewProperty1 {get;set;}
      public string NewProperty2 {get;set;}
  
      public NewClass(){}
      public NewClass(ExternalClass externalClass){
          this.ExternalClass=externalClass;
      }
  }
  </code></pre>
  
  <p>But to convert by original list of the external classes to a list of the new classes I would have to create a new list of new classes and iterate through the original list creating a new object and adding it to the list, like</p>
  
  <pre><code>List&lt;NewClass&gt; listOfNewClass=new List&lt;NewClass&gt;();
  foreach(var externalClass in listOfExternalClass)
  {
      listOfNewClass.Add(new NewClass(externalClass));
  }
  </code></pre>
  
  <p>I would then be able to access the external properties like</p>
  
  <pre><code>listOfNewClass.FirstOrDefault().ExternalClass.EXproperty1;
  </code></pre>
  
  <p>Can I do this with inheritance or is there a more efficient method?</p>
  
  <p>Ideally I would like to end up with by calling the properties like:</p>
  
  <pre><code>listOfNewClass.FirstOrDefault().EXproperty1;
  </code></pre>