1

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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).

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.