Automatic C# Class Code Generator

A common task (for me anyway) is reading a large text file, processing each line in some way, and then writing results to a second file. For example, suppose you have a text file that begins like:

  • 187,Smith,Chris,D,06/15/1985,developer,45.60
  • 213,Jones,Steve,M,11/21/1978,manager,52.35

Here we have an employee ID, last name, first name, middle initial, date of birth, job title, and pay rate. And suppose you want to read this file and then for each employee add some new column that depends on their date of birth and pay rate. A good way to organize this is to create a class for the input and a class for the output. I do this a lot, with many different types of files, often with 20 or more fields. It got real old creating class after class. So I took a half a day to write an application that accepts a class name (like Employee), and a list of field names and types (int empID, string last, and so on), and then generates all the template code I need to copy and paste into my program.  This is one time when taking time to create a tool has saved me tons of time.


This entry was posted in Software Test Automation. Bookmark the permalink.