I wrote some general deserialization mechanism that allows me to create objects from the binary file format used by the C ++ application.
To make things clean and easy to change, I created a class Fieldthat extends Attribute, builds with Field(int offset, string type, int length, int padding)and applies to the class attributes that I want to deserialize. Here's what it looks like:
[Field(0x04, "int")]
public int ID = 0;
[Field(0x08, "string", 0x48)]
public string Name = "0";
[Field(0x6C, "byte", 3)]
public byte[] Color = { 0, 0, 0 };
[Field(0x70, "int")]
public int BackgroundSoundEffect = 0;
[Field(0x74, "byte", 3)]
public byte[] BackgroundColor = { 0, 0, 0 };
[Field(0x78, "byte", 3)]
public byte[] BackgroundLightPower = { 0, 0, 0 };
[Field(0x7C, "float", 3)]
public float[] BackgroundLightAngle = { 0.0f, 0.0f, 0.0f };
The call myClass.Decompile(pathToBinaryFile)will then retrieve data from the file by reading the correct types and sizes at the correct offsets.
However, I believe that passing a type name as a string is ugly.
Is it possible to convey a type in a more elegant and shorter way, and how?
Thank.