title: Why does this cloning not work?
body: <p>I'm trying to clone instances of a derived class, but somehow it doesn't work well. The cloning method is:</p>
  
  <pre><code>public static T CloneFieldsAndProperties&lt;T&gt;(T input)
  {
      T result = (T)Activator.CreateInstance(typeof(T));
      PropertyInfo[] listOfProps = typeof(T).GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.CreateInstance);
      FieldInfo[] listOfFields = typeof(T).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.CreateInstance);
      foreach (PropertyInfo prop in listOfProps) prop.SetValue(result, prop.GetValue(input, null), null);
      foreach (FieldInfo field in listOfFields) field.SetValue(result, field.GetValue(input));
      return result;
  }
  </code></pre>
  
  <p>As you can see, I added many <code>BindingFlags</code> because it wasn't working. But to no avail.</p>
  
  <p>It <em>does</em> work in a simple case:</p>
  
  <pre><code>MyclassA1 a1 = new MyclassA1();
  MyclassA a = CloneFieldsAndProperties(a1);
  if (a is MyclassA1) Text = "Works";
  </code></pre>
  
  <p>Where:</p>
  
  <pre><code>class MyclassA
  {
      public int i;
  }
  
  class MyclassA1 : MyclassA
  {
      public int i1;
  }
  </code></pre>
  
  <p>But in my real program it doesn't. The real program's classes' declarations are long so I'm not posting them here. What might be the problem?</p>