title: Dynamically Assigning Values to a Child Class in C#
body: <p>How can I dynamically load a Child Class in C# based upon values from its inherited class?</p>
  
  <p>I have a class that inherits an entity, and since I cannot cast a parent class to its child type I want to dynamically load the entity data without explicitly defining each property.</p>
  
  <p>I tried doing it by looping using a foreach loop, but as you know you cannot assign values to foreach variables.</p>
  
  <p>My Failed Attempt:</p>
  
  <pre><code>public class ABroker : DP_ePAFBroker
  {
      public ABroker() : base()
      {
      }
      public ABroker(DP_ePAFBroker data)
      {
          var props = typeof(DP_ePAFBroker).GetProperties();
          foreach(object obj in this)
          {
              foreach (var prop in props)
              {
                  obj = prop.GetValue(obj, null);
              }
          }
  
      }
      public IEnumerator GetEnumerator()//List of Objects
      {
          var props = typeof(DP_ePAFBroker).GetProperties().Select(p).ToList&lt;Object&gt;();
          return props.GetEnumerator();
      }
  }
  </code></pre>