Original Post
Hi, guys. I''m making an RPG with C#. I''m having trouble with deciding how to deal with saving/loading maps, tiles, characters, weapons, etc. I also want a method that is backwards/forwards compatible. This is the best I can think of so far, please tell me if I''m approaching this the right way:
1. Make SinceAttribute and DeprecatedSinceAttribute attribute classes that accept an (int version) parameter in the constructor.
2. Tag all class members that I want to record with these attributes as needed. For example, if CurrentVersion of the class is 6, and I want to add a member to this class, I''ll change CurrentVersion to 7, add the member, and tag the member with [Since(7)].
3. Make all saveable/loadable classes implement this interface:
public interface IRecordable
{
IRecordable(SerializationInfo info, StreamingContext context); //Don''t know if I can do this. Just let me know if I can''t.
String name {get;set};
int CurrentVersion {get};
}
4. Make all saveable/loadable classes implement ISerializable.
5. In GetObjectData(), record CurrentVersion first, and then all the members whose SinceAttribute is <= CurrentVersion and whose DeprecatedSinceAttribute is > CurrentVersion.
6. In Constructor(SerializationInfo info, StreamingContext context), read in CurrentVersion first, and then all the members whose SinceAttribute is <= CurrentVersion and whose DeprecatedSinceAttribute is > CurrentVersion.
Please tell me if this is a good way to go about recording my game info. Thanks in advance.