In the case of only 10 cases that will rarely change, several methods using Switch statements may suffice.
If you have control over static objects, they can all implement a new interface that returns the character "serialization code":
public interface IStaticObject { char SerializationCode { get; }; }
Therefore, moving in this direction is easy: someObject.SerializationCode. Then you can also use your static objects using a constructor that registers its SerializationCode with a singleton instance that has a dictionary.
public class SomeStaticObject : IStaticObject { public void SomeStaticObject() { StaticObjectRegistrar.Register(this.SerializationCode, this); } public char SerializationCode { get { return ?; } } }
Deserializing, you just take a character and run it through this dictionary to return a static object.
Scott whitlock
source share