I have a Windows Phone application I am developing that needs to persist some objects to IsolatedStorage. Isolated Storage is pretty handy in that you can just pop an object into in using a few lines of code.
I need a few more objects persisted where the type is different but the method of persisting is not. What I was going to do was simply cast my types to object, save them and when retrieving them cast back to the particular type needed.
Because of conventions used by the app I always know which cast to perform but I wonder if doing this would cause me to loose anything during the cast / recast of the object.
EDIT: I would like to point out that the comments have showed me that I was actually looking for generics without knowing that they solve my issue. I have upvoted everyone who suggested them as they took apart my question and found the crux of my dilemma. Thanks to all that suggested them.
Generics is perfect for this scenario. There’s an example of how to create generic methods that read and write to an Isolated Storage here.