Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy way to generate code from a text file?

I am currently working on a project that is accessing a piece of hardware using tons of hard coded memory locations. These locations can change based upon the electrical engineer's whim, so I'm looking to generate code from the engineer's memory map. Let's say the map is a simple text file like:

Name, Type, Address, Description
Foo, int, A001, Foo integer variable
Bar, float, A002, Bar float variable

I would like to automatically generate code (not IL) similar to:

class MachineMap
{
  /// <summary>
  /// Foo integer variable
  /// </summary>
  public readonly Addressable<int> Foo = new Addressable<int>("A001");
  /// <summary>
  /// Bar float variable
  /// </summary>
  public readonly Addressable<float> Bar = new Addressable<float>("A002");
}

Does anyone have ideas on tools that would make this task easy, or easier?

like image 332
Scott P Avatar asked Mar 10 '10 19:03

Scott P


1 Answers

Have a look at the built-in code generation ability of Visual Studio called T4. Or another option might be commercial product such as CodeSmith.

Have a look at this article from Scott Hanselman:
T4 (Text Template Transformation Toolkit) Code Generation - Best Kept Visual Studio Secret

like image 137
Philip Fourie Avatar answered Oct 28 '22 21:10

Philip Fourie