C #define to C# constant converstion tool
-
I am looking at a series of header files with thousands of #define statements in them. I have been tasked with writing a utility that utilizes these defines in C#. I know that I can manually convert these, but unfortunately they are living files and I would have a maintenance nightmare. My question is does anyone have or used any utilities that can be run has a pre-build process from inside VS that converts header file #define to C# constant? Any help on this is greatly appreciated! ~Mike
-
I am looking at a series of header files with thousands of #define statements in them. I have been tasked with writing a utility that utilizes these defines in C#. I know that I can manually convert these, but unfortunately they are living files and I would have a maintenance nightmare. My question is does anyone have or used any utilities that can be run has a pre-build process from inside VS that converts header file #define to C# constant? Any help on this is greatly appreciated! ~Mike
You can use the utility MSBuild Task[^] that provides the code that runs during the build process. You need to include the code to convert header file #define to C# constant
-
I am looking at a series of header files with thousands of #define statements in them. I have been tasked with writing a utility that utilizes these defines in C#. I know that I can manually convert these, but unfortunately they are living files and I would have a maintenance nightmare. My question is does anyone have or used any utilities that can be run has a pre-build process from inside VS that converts header file #define to C# constant? Any help on this is greatly appreciated! ~Mike
I use the C pre-processor and then pass the result to CSC. But I don't know about integrating that with VS. One of the problems with trying to automatically convert it is that the macroes don't specify a type. Another solution would be to store the items in XML and then use XSLT to produce either C/C++ (h) or C# code as required.
-
I am looking at a series of header files with thousands of #define statements in them. I have been tasked with writing a utility that utilizes these defines in C#. I know that I can manually convert these, but unfortunately they are living files and I would have a maintenance nightmare. My question is does anyone have or used any utilities that can be run has a pre-build process from inside VS that converts header file #define to C# constant? Any help on this is greatly appreciated! ~Mike
Yeah, tricky. Interesting problem too. I guess you're right, have a prebuild step which parses the #defines and spits out constant integers. I know of no such tool, but should be easy to write yourself. I've got some vague recollection that .NET doesn't stash constant integers in metadata but resolves them to numbers during main compilation. If this is correct, if your constants are used outside the assembly they're defined in, you'd need to rebuild that assembly as well. Just replacing the one assembly don't work. Perhaps someone here could confirm that or tell me I dreamt it.
Regards, Rob Philpott.
-
I use the C pre-processor and then pass the result to CSC. But I don't know about integrating that with VS. One of the problems with trying to automatically convert it is that the macroes don't specify a type. Another solution would be to store the items in XML and then use XSLT to produce either C/C++ (h) or C# code as required.
-
Interesting idea...I have a question as to what and how you pass data from the C pre-processor to the CSC? Thanks everyone for you thoughts!
"C:\mingw\bin\cpp" -P -C -w %1.cs %1.csi csc.exe @"C:\batfiles\Build.rsp" %1.csi
-
"C:\mingw\bin\cpp" -P -C -w %1.cs %1.csi csc.exe @"C:\batfiles\Build.rsp" %1.csi
-
Thanks PIEBALDconsult...Couple questions 1. Is this entered at the command-line or via a batch file? 2. The "C:\mingw\bin\cpp" reference. Where is this from? Thanks again!
Those are part of my CC.BAT file. http://www.mingw.org/[^] I'm trying to remember where I got the installer I used, at the moment I can't even find the file I downloaded. Ah, I remember; at one point I had installed Quincy[^] and it installed MinGW. When I built my current system I simply copied the directory tree over.
modified on Thursday, June 11, 2009 2:58 PM
-
Those are part of my CC.BAT file. http://www.mingw.org/[^] I'm trying to remember where I got the installer I used, at the moment I can't even find the file I downloaded. Ah, I remember; at one point I had installed Quincy[^] and it installed MinGW. When I built my current system I simply copied the directory tree over.
modified on Thursday, June 11, 2009 2:58 PM