title: Is there a way to programmatically extract an Interface?
body: <p>Say I have a .NET class like so:</p>
  
  <pre><code>public class Person {
      public string Name { get; set; }
      public int Id { get; set; }
  }
  </code></pre>
  
  <p>Visual Studio has a nifty refactoring tool called Extract Interface that will extract an <code>IPerson</code> interface, and have <code>Person</code> implement it. Is there a way to do that programmatically from outside of Visual Studio? I'd even take a shell script if it can't be done programmatically. </p>
  
  <p>[EDIT]
  In actuality, I would have up to 50 classes, each with dependencies on each other.</p>
  
  <p>Reflection would work, but it would introduce another wrinkle into the whole thing. The classes are already generated by <code>xsd.exe</code>. So, if I understand it correctly, the steps I would need to take would be:</p>
  
  <ol>
  <li>Generate classes from <code>xsd.exe</code>.</li>
  <li>Compile the classes on the fly so that I can use reflection. </li>
  <li>Reflect over them, emit the interfaces, and edit the original classes to
  implement said interfaces.</li>
  </ol>
  
  <p>Generally I'd be in favor of just ditching the interfaces and using the classes directly, but for various reasons I cannot.</p>