This post is a bit random. I’m not feeling well today, but I had an idea while staring into space and decided I shouldn’t waste it.
I thought about the XNA Content Pipeline, and the convenience of reflection-based serialization. I thought about the run-time performance penalty you pay for that convenience, and suddenly realized that you can have the best of both worlds.
What if the reflection-based XNB serializer also generated source code for a ContentTypeReader? Then you’d have the convenience of automatic serialization at build time, and the performance of custom deserialization at run-time! The source code for all the generated content readers could be compiled by the content pipeline into an assembly and deployed along with the rest of the content. Then, when the content pipeline needs to read the types at run-time, it would use the (automatically-generated) custom readers instead of reflection.
Since I’m not sure I want to make this my keep-busy-while-sick project, I’m throwing the idea out there to see if anyone else wants to try it. If you try, but get stuck, I’ll be happy to help by answering questions about dynamic code gen or msbuild customization.
A couple references to get you started: