Reputation: 2197
So here's the background: We have a legacy program that writes data logs in C++. the data is contained in different structures. The program that reads the log files uses those same structures to display the data. I rewrote the program that reads the log files and C# and had to create C# copy of all those structures by hand. Is there a better way to do this? I have considered setting up a lookup path to the structures and a sort of parser that would generate a C# structure at build time, but it seems excessively complicated to handle all the special cases. Are there any suggestions to do this? it seems kind of ridiculous that C# doesn't have any backwards compatibility to handle C/C++ structures.
Upvotes: 2
Views: 208
Reputation: 1837
Summary of your problem: You have a large number of structs in an existing C++ program that you serialize to disk. You want to port the structs to C# so you can deserialize the data from disk into your C# program. You don't just want to do this once. You want to keep the two sets of structs in sync as both programs evolve.
What you need is an Interface Definition Language (IDL) in which you can describe your data in a language independent way. Something like Apache Thrift, Google Protocol Buffers or MessagePack.
The steps you'd have to take would be:
The disadvantages are:
I think this is outweighed by the advantages:
Upvotes: 0
Reputation: 33149
How many structures are there and how complicated are they?
It's a costs vs benefits question I'd say. I'll bet that, judging from your question, just quickly coding the structs in C# is the best way to go.
Just my 2 cents, before taxes...
Upvotes: 1