Exporting Objects from the Visual Studio Debugger

I had been searching for a way to export objects from my debugging windows (ex. locals, autos, watch) to their C# object initialization code for creating unit tests. There have been a few cases where there are some complex objects that I load through a database which would make great unit tests. Unfortunately i was not able to find anything like that, so I decided to create it myself. Enter Object Exporter.


Object Exporter is accessed through the tools menu and is only visible when you are debugging.

Export Objects (Tool Menu)

Once selected a dialog is shown with settings for the Object Export.

Export Objects (Select Objects)

The Output Format details which format you want your exported objects to be in. Maximum Object Depth refers to the maximum depth the Serializer will generate text for, this is important as some objects can have an infinite depth. Once you select a debugging window from the drop down, it’s objects will be loaded onto the screen and you may check the objects you wish to export.

The objects which can be selected correspond to the objects that exist within the various windows:

Export Objects (Locals)

Once the objects are selected and the “Export” button is selected, another dialog with the generated texts appear:

Export Objects (Xml Generated)

Export Objects (Json Generated)

Export Objects (CSharp Generated)

You can copy the text in the currently selected tab by selecting “Copy To Clipboard” or you can save all the objects to a folder by selecting the “Save All to Folder” button, a file per tab will be generated.

That’s pretty much it.


Automatically generating Repository and Unit Of Work classes

In my projects I usually access all my data through a repository. The utilization of the repository pattern provides a number of benefits for your code:

  1. Reduces duplicate data access code.
  2. Data access code can be isolated/faked for Unit Testing.
  3. Allows you to swap other ORMs, databases or data access code without affecting other parts of the system.

The only draw back to using a repository pattern is that it can be cumbersome to implement (especially if you have a lot of models), to help with that I’ve created a NuGet package which will generate Repository and Unit of Work classes with basic Get, Get All, Delete, Update code implemented in an abstract Generic Repository (so they can be freely overridden).

The NuGet package is available here:



The NuGet package will add a RepositoryGenerator.tt which will generate the following classes:

Repository.cs: An abstract class with basic implementation of Get, GetAll, Delete and Update

IRepository.cs: An interface for the abstract class

UnitOfWork: A unit of work class for committing all changes at once.

IUnitOfWork: The interface for the unit of work.

In addition to these classes, a repository and interface will be generated for each one of your entities allowing you to extend beyond the basic functionality provided by the generic repository.

With the Repository Generator NuGet package you should be up and running with a repository within a just few seconds!


Generating C# Classes from Excel

A while back I was tasked with converting and migrating data from an existing accounting system to a new one, (un)fortunately this was not the first time I was asked to do a data conversion. A year prior I had to migrate data from a 20 year old legacy system to a new software solution.

While the systems were completely different I was able to reuse a lot of the patterns and helper libraries which I had used before. During the first data conversion I felt a large portion of my time was wasted creating classes for the corresponding excel input and output files. I thought if I could generate classes with properties corresponding to the excel columns and their types, that it might save some unnecessary typing to create those classes.

So i created ExcelToClasses, a NuGet package which will open an .xls file and convert each worksheet to a class and each column to a property within that class.

The NuGet package can be found here:


The package will add some T4 templates to your project, all that’s needed is to open the DataConversion.tt file and supply one or many paths to the excel file(s) and save the DataConversion.tt file.

A .cs file will be generated per worksheet, each property will have an attribute with the name and position of the corresponding excel column. This will be very useful if you are generating classes for the output schema (the format of the new system) and you wish to rename the properties or change their position in the class without affecting the output file to be generated.