title: How to workaround missing ICloneable interface when porting .NET library to PCL?
body: <p>I am porting an existing .NET class library to a Portable Class Library. The .NET library makes extensive use of the <a href="http://msdn.microsoft.com/en-us/library/system.icloneable.aspx">ICloneable</a> interface, which is not included in the portable subset. </p>
  
  <p>Typically, I am faced with class definitions like this in the .NET class library:</p>
  
  <pre><code>public class Foo&lt;T&gt; where T : ICloneable
  {
      public void Bar(T item) {
          var x = item.Clone();
          ...
      }
  }
  </code></pre>
  
  <p><em>What can I do to successfully port this code to a Portable Class Library? Do I have to rewrite the <code>Clone</code> method invocations, or is there a less intrusive workaround?</em></p>
  
  <p>I cannot simply remove the generic type constraint <code>where T : ICloneable</code> because then the <code>Bar</code> method will not compile.</p>
  
  <p>I could write up a replacement interface to use instead of <code>ICloneable</code> in the ported code:</p>
  
  <pre><code>public interface IPCLCloneable {
      object Clone();
  }
  </code></pre>
  
  <p>This would work as long as I only instantiate <code>Foo&lt;T&gt;</code> with classes that implement <code>IPCLCloneable</code>, but it <em>will not work</em> for example with types from the core libraries that implement <code>ICloneable</code>, such as <a href="http://msdn.microsoft.com/en-us/library/System.Array.aspx">Array</a>:</p>
  
  <pre><code>var x = new Foo&lt;int[]&gt;();  // Compilation error in PCL library
  </code></pre>
  
  <p>(For completeness, it should be pointed out that the <code>ICloneable</code> interface is not explicitly implemented in the portable subset core libraries since it does not exist, but the <code>object Clone()</code> method does exist in the portable subset <code>Array</code> class, and consequentially for array implementations such as <code>int[]</code>.)</p>
  
  <p>What other options do I have?</p>