views:

388

answers:

2

I was wondering if there was a built in runtime parser for header files in C#. I have several different C header files that I want to parse (They will later be used to determine how a network packet will be deserialized).

Ideally, some option to load the .h file dynamically, create the struct, and then use reflection to somehow parse the struct, just not certain if there's a way to load the .h file at runtime to create the struct.

If there is no easy way to do this, I can just parse it manually.

+1  A: 

No, there is no standard means by which to do this, and given that there isn't exact parity between C types (which vary with compilers and platforms) and CLR types, I don't know that a completely generic one could be written.

You're much better off parsing the data yourself.

Adam Robinson
Ok, thank you, manual parsing is fine with me.
CookieOfFortune
A: 

This comes pretty close: http://www.swig.org/

It is a wrapper generator that can read C++ files and generate wrappers in C# (or lots of other languages).

consultutah
Swig is nice, but this seems like a borderline case where manually wrapping the files involved may be easier than dealing with integrating swig into the workflow.
Eric
That seems very interesting, but the parsing I'm doing isn't very complicated (I write the header files anyways). But I will keep this in mind.
CookieOfFortune