Lombok.NET icon indicating copy to clipboard operation
Lombok.NET copied to clipboard

Generator To Serialize/Deserialize Objects

Open furesoft opened this issue 1 year ago • 6 comments

It would be really nice to have a generator to serialize/deserialize objects to binary.

Example:

[Serializeable]
public partial class MyClass {}

that generates two methods, one for serialisation with a binarywriter and one for deserialisation with binaryreader

furesoft avatar Jul 06 '23 11:07 furesoft

That's a great idea. Unfortunately I'm a bit swamped at the moment and will only be able to get to this in a couple of weeks.

In the meantime, I'd be happy to accept a PR in case you're interested.

CollinAlpert avatar Jul 06 '23 11:07 CollinAlpert

@furesoft I have started working on this, but am not quite sure what you are proposing. Using BinaryFormatter is discouraged, so maybe you could share what the generated code should look like?

CollinAlpert avatar Aug 07 '23 10:08 CollinAlpert

Using BinaryWriter and BinaryWriter and serialize/deserialize obeject froms scratch

furesoft avatar Aug 07 '23 12:08 furesoft

Hey, I had the same idea, I think, so I would share this here: https://github.com/xafero/csharp-generators/blob/main/src/Cscg.Compactor/CompactGenerator.cs

Generating a read and write method for every property in the class with BinaryReader and BinaryWriter.

xafero avatar Mar 26 '24 13:03 xafero

@xafero That looks great! Would you like me to add that to this library?

CollinAlpert avatar Mar 26 '24 15:03 CollinAlpert

@xafero That looks great! Would you like me to add that to this library?

Sure. Maybe my code is rough, but I saw this issue and wanted to maybe help. Because I like Lombok and your take on it.

xafero avatar Mar 26 '24 15:03 xafero

Available in v2.4.0

CollinAlpert avatar Jun 30 '24 15:06 CollinAlpert