i wrote generic deserialization mechanism allows me construct objects binary file format used c++ application.
to keep things clean , easy change, made field
class extends attribute
, constructed field(int offset, string type, int length, int padding)
, applied class attributes wish deserialize. how looks :
[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 };
calling myclass.decompile(pathtobinaryfile)
extract data file, reading proper types , sizes @ proper offsets.
however, find passing type name string ugly.
is possible pass type in more elegant yet short way, , how ?
thank you.
use typeof
operator (returns instance of type
):
[field(0x7c, typeof(float), 3)]
Comments
Post a Comment