views:

42

answers:

1

On my current project we are using both binary and xml serialization to store data that relates to user settings in a winforms application.

Currently, we have two challenges:

  1. Serialization is being implemented via attributes on classes that also have business logic woven into them.
  2. It is difficult to re-factor these classes without affecting the ability to retrieve already stored data.

My main goal is to isolate a data contract so that it doesn't dilute or constrain other logic and so that I can provide a migration path for existing data when needed.

+1  A: 

Why not create a peer serializable object who's role is simply to support serialization/deserialization? The serializable class can either have methods on it that are used to push/pull the real object in and out of serialization or you could use a separate data mapping class (this might be better if you have serious versioning concerns).

That way your main application object(s) are persistent ignorant and you don't have to make compromises - like public getters and setters and attributes - just to support serialization. The end result will be a serialization layer which is decoupled from changes to the application layer.

In n-tier applications these are usually refered to as Data Transfer Objects (DTOs) although the term isn't usally applied in the case your describe here.

Ade Miller
you can use http://www.codeplex.com/AutoMapper to map your business objects to DTOs.
zvolkov