title: Debugger Visualizer to generate Object Initializer code
body: <p>We have a bug to fix, and like any good TDD practitioner, I want to write a failing test to represent the bug first.  The bug is in a method that takes a rather complex type as input.  The bug will only reproduce when the complex type has a certain combination of property values set.</p>
  
  <p>So far I have reproduced the bug and, in the debugger, can view the run-time value of the complex type.  Now I need to create that complex type in the "Arrange" section of my unit test so that I can feed it to the buggy method in the "Act" section of the unit test.</p>
  
  <p>I can write a big object initializer code block, by hand, such as the following one:</p>
  
  <pre><code>var cats =
      new List&lt;Cat&gt;
          {
              new Cat {Name = "Sylvester", Age = 8},
              new Cat {Name = "Whiskers", Age = 2}
          };
  </code></pre>
  
  <p>or even something like this:</p>
  
  <pre><code>var cats = new List&lt;Cat&gt;();
  var cat1 = new Cat();
  cat1.Name = "Sylvester";
  cat1.Age = 8;
  cats.Add(cat1);
  var cat2 = new Cat();
  cat2.Name = "Whiskers";
  cat2.Age = 2;
  cats.Add(cat2);
  </code></pre>
  
  <p>Nothing fancy there.  The only problem is the "by hand" part -- the complex type in my case is not nearly as trivial as the above example.</p>
  
  <p>I can also view the object, while in the debugger, with any of the built-in debugger visualizers.  So I figured I would write a custom Debugger Visualizer that will generate the object initialization code for me.  To use it, I would reproduce the issue in the debugger, pull up the QuickWatch window and select my custom visualizer.</p>
  
  <p>Another option would be to write a custom serialization implementation that would "serialize" to a block of object initialization code.  To use this would be a bit harder than just pulling up the QuickWatch window, but this could work.</p>
  
  <p>Before I tackle this problem myself, has anybody done something like this?  Mind sharing a code snippet?  Or would anyone suggest another approach?</p>
  
  <p>P.S.  In my case, the type of the object is a subclass of an abstract base class.  Just wanted to mention it.</p>