title: Creating a cloned copy of subclass from baseclass
body: <p>Consider this scenario:</p>
  
  <pre><code>public class Base
  {
      public int i;
  }
  
  public class Sub : Base
  {
      public void foo() { /* do stuff */}
  }
  </code></pre>
  
  <p>And then I want to, given an instance of <code>Base</code> get an cloned instance of <code>Sub</code> (with i=17 in this case) so that I can call <code>foo</code> in the subclass. </p>
  
  <pre><code>Base b = new Base { i=17 };
  Sub s = CloneAndUpcast(b);
  s.foo();
  </code></pre>
  
  <p>However, how can I create <code>CloneAndUpcast</code>?</p>
  
  <p>I am thinking that is should be possible to recursively clone all of <code>Base</code>-members and properties using reflection. But quite some work.</p>
  
  <p>Anyone with better, neater ideas?</p>
  
  <p>PS. The scenario where I am thinking about using this is a set of "simple" classes in a tree-like structure (no cyclic graphs or similar here) and all the classes are simple value holders. The plan is to have a stupid layer holding all values and then an similar set of classes (the subclasses) that actually contains some business-logic the value-holders shouldn't be aware of. Generally bad practice yes. I think it works in this case.</p>