I would like to use the .tt file to process the .h and turn it into a .cs file. Its very easy and the source files will become part of your C # solution (which means that they will be updated as the .h file changes), you can click to open it in an editor, etc.
If you have only 1 #define, this may be a bit crowded, but if you have a complete file (for example, the mfc resource.h file), then this solution will be a big win.
for example: create a DefineConverter.tt file and add it to your project, change the marked line to access your .h file, and you will get a new class in your project, full of static const entries. (note that the input file refers to your project file, set hostpecific = false if you want absolute paths).
<#@ template language="C#v3.5" hostspecific="True" debug="True" #> <#@ output extension="cs" #> <#@ assembly name="System.Core.dll" #> <#@ import namespace="System" #> <#@ import namespace="System.Collections.Generic" #> <#@ import namespace="System.IO" #> <# string input_file = this.Host.ResolvePath("resource.h"); <---- change this StreamReader defines = new StreamReader(input_file); #>
gbjbaanb
source share