Lets say you have various objects of arbitrary type that you would like to store in a key+value type of table. Key could for example be an int, string or guid. What would the value be? String, Binary or something else?
And how would you store and load the objects? I would think some sort of serialization, but what kind?
I have one solution at the moment where I have a class with these two methods:
public T Get<T>(string key)
public void Set<T>(string key, T value)
In the database I have a table with a string column and a binary column. I then use a BinaryFormatter
to serialize and deserialize the value and Linq2Sql to put the binary result in the database table. But is this a good solution? Currently I have only dared trying this with simple values like integers and strings. How do the BinaryFormatter
and serialization in general work with more complex types like structs and class? Especially if for example the value contains things like arrays or lists.
Any pointers?
At the moment I will be using it to store various last-selected-or-typed-etc type of values. Although they may not always necessarily be typed. For example it may be choosing values from a list. Main point is that they will pretty much be just convenience stuff for the user, so not very critical data.