title: Serialize alread-built instance of a WinForms.Form to VB or C# Sourcecode, just like the IDE does
body: <p>I have about 500 WinForms that are generated dynamically from XML files by an old app. I would like to automatically convert these to VB or C# code I can edit in the designer.</p>
  <p>I can do it by hand, which would take forever...</p>
  <p>Or write an app that loads each XML, calls the old app's xml-to-winform-builder to convert it to a completed WinForm, and examine every control's property and use StringBuilder to generate code that the designer will swallow. Which would be arduous at best.</p>
  <p>BUT: I would like to use the same code that the designer uses. This I think will save me time with corner cases.</p>
  <p>What I would like to do is, take an already built WinForm object, with control arrays full of child controls (created by the old apps xml-to-winform code), throw it at the same code the IDE uses to serialize the designed form to CodeDom, and get back a CodeDom list of statements I can save in a real language. Once I get the CodeDOM I'll be happy!</p>
  <h3>EDIT</h3>
  <p><a href="http://www.codeproject.com/Articles/9307/Converting-WinForms-Web-Forms-using-CodeDom" rel="nofollow noreferrer">This Codeproject</a> article embodies the 'concept' of what I want to do: Start with a completed form, convert it ('serialize it') as code. However, it has two lacks: (1) it generates the .aspx page using templates/stringbuilder, and that is where the properties are (fine for webforms, but winforms serializes the properties into the actual .Designer.vb file); (2) it does this all from the ground up. I want to re-use visual studio's routines. They let you do this with many things, for example, the property grid. I'm just seeking a link to an article (maybe my google-fu was too weak), or, a short code sample from something somebody has already done.</p>