- #1
twoski
- 181
- 2
Let's say i have a class which is not my own code. It is not serializable using the .NET serialization utilities.
In order to save the pertinent data for this class i have created a serializable version of the class and have conversion methods which allow me to essentially convert the class to a serailization friendly class.
This works fine if there is only one class, but what if i have several subclasses deriving from this class?
From the serialization perspective, it would be impossible to distinguish one from another. All of them have more or less the same data. Their type is the only thing that differs.
How can i make a generic method for saving the class type, and then instantiating that specific type when i deserialize?
One way i could do it is save a string/enum that tells me what class to instantiate when i deserialize. This sounds hacky to me though. There must be a better, more robust solution.
In order to save the pertinent data for this class i have created a serializable version of the class and have conversion methods which allow me to essentially convert the class to a serailization friendly class.
This works fine if there is only one class, but what if i have several subclasses deriving from this class?
From the serialization perspective, it would be impossible to distinguish one from another. All of them have more or less the same data. Their type is the only thing that differs.
How can i make a generic method for saving the class type, and then instantiating that specific type when i deserialize?
One way i could do it is save a string/enum that tells me what class to instantiate when i deserialize. This sounds hacky to me though. There must be a better, more robust solution.