views:

96

answers:

1

This is a three part question.

One: Would using a

Dictionary<String,Object>

be a good way of saving data where it would be

Dictionary<Key,Value>

as the basis?

Two: What would be a better way without using app.settings or xml?

Three: How would you serialize this(Or the better solution) into a binary format that is compact and serializes quickly?


Xml is very verbose and I was looking for binary due to it's size.
Also, if I used Dictionary, it would have been easy to make a settings class with simply

GetValue(Key) and SetValue(Key,Obj)
or object.SetValue(Settings,Key) using extensions.

I am making my application open for plugins so I wanted a uniform spec for settings that all applications use.

Rolling my own class using Dictionary as the basis made sense if I could serialize it into a file.

+1  A: 

Try using protobuf-net. This would solve all three of your problems. I looked at it last week, and replaced my entire xml-based messaging infrastructure in just a couple of days. Marc Gravell is a frequent contributor on here, and he was very prompt and helpful in his replies to my queries.

Carlos
How would I use this for settings? Can it serialize a dictionary?
AKRamkumar
Yes, you can serialize a dictionary. In fact, I did this in my solution.For "Settings" I take it you mean that you want to store some values and restore them later, as in save/load?This would be easy. You'd take your object that you want to save, generate a serialized representation, and save that. Then deserialize it when you like.The only issue is that protobufs saves stuff in a very compact binary form, so you wont be able to visually recognize that the stuff is saved correctly. But it will still work.
Carlos
Does it support Generics in that a dictionary<string,object> would still serialize? Since this is a wrapper around a dictionary, would protobuf-net serialize the dictionary instance inside the settings class?Basically I am implimenting a key-value system in the dictionary where both the key and the value need to be serialized.sorry if I am sounding a bit noobish, I am still learning programming.
AKRamkumar
I think there's an issue around serializing object, because it doesn't quite know how to do it. That's where I had to make some small changes to my structure. Marc says V2, which is out sometime soon, will address this. BTW, there's a stackoverflow question about this somewhere, but I forget what it was. But the question specifically has an example where someone tries to serialize object, and Marc came up with a solution.
Carlos