Sign in to follow this  

[.net] Serialization Best Practices

This topic is 3729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering what everyone is using for serialization for their .Net projects, especially when it comes to loading (and saving) scene information. The ISerializable interface works great with it's GetObjectData method combined with a protected constructor. The serialization of generic containers works perfectly. Unfortunately, I want my data stored in XML for easy editing, but only the BinaryFormatter supports generics. Plus even if the SoapFormatter supported generics, it generates very hard to read XML. The XmlSerializer class also doesn't support generics, but more importantly, doesn't ignores the GetObjectData and protected constructor, requires a empty public constructor, and only supports serializing public fields. I don't want to have to create my own custom methods for serialization/deserialization and rather use something that's already build in to the framework. Unless I'm missing something, it looks like the framework is lacking in the ability to easily support semi-complex serialization to XML. I would prefer any solution to remain compatible with the Compact 2.0 framework so it can be easily ported to the Xbox 360. Anyone willing to share some techniques and/or your experiences with XML serialization in .Net?

Share this post


Link to post
Share on other sites
I never found a good solution and ended up writing my own XML serializers. Luckily it's not too complex; my latest serializer is ~600 lines of C# with lots of comments and parameter validation.

The closest solution that is "built-into" .NET is XamlReader, but that requires .NET 3.0. Plus I don't think XAML supports generics.

Share this post


Link to post
Share on other sites

This topic is 3729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this