title: How to deep copy array items with unknown type at runtime without using MakeGenericMethod?
body: <p>I got an System.Object (AKA object) that is simple one-dimensional array (I do a lot of checks). The element type will become known at runtime. I have to do two types of copying the array:</p>
  
  <p>1) deep copy array itself but shallow copy items:
  - this has answer here: <a href="https://stackoverflow.com/questions/58475741/how-to-convert-ilist-of-unknown-type-type-is-known-at-runtime-to-array/58475917#58475917">my previous question</a>
  2) deep copy array itself as well as its items:</p>
  
  <p>I did it like that:</p>
  
  <pre><code>public object FullDeepCopy_SimpleArray(object original)
  {
  
      Type elementType = original.GetType().GetElementType();
      return GetType()
              .GetMethod("Create_DeepCopyArray")
              .MakeGenericMethod(elementType)
              .Invoke(this, new object[] { original });
  }
  
  //used in generic invoke
  public T[] Create_DeepCopyArray&lt;T&gt;(object original)
  {
      T[] origArray = (T[])((Array)original).Clone();
  
      int length = origArray.Length;
      T[] copy = (T[])(Array.CreateInstance(typeof(T), length));
  
      for (int i = 0; i &lt; length; i++)
      {
          copy[i] = (T)Create_infDeep_CopyOf(origArray[i]);    // this makes the deep copy of any item
      }
  
      return copy;
  }
  </code></pre>
  
  <p>It works perfectly but it raises some problems:</p>
  
  <ul>
  <li>it's unsecure to work with, other programmers might delete the method <code>Create_DeepCopyArray</code> as it is only used in <code>GetMethod</code> code and IDE Visual Studio doesn't recognize it as used (because it's passed as string)</li>
  <li>Look at the number of casts in <code>Create_DeepCopyArray</code> method, I kind of think there must be a better solution</li>
  </ul>
  
  <p>Do you have any ideas to improve this?</p>