
Replacement for INI Files?
Quote:
> I am trying to think through what I should use as a logical
> replacement for ini files since they have been obsolete for a while
> now.
I also stopped to use INI files. What's more - I've found app.config file
not quite convenient.
Instead, I have a public class called CMyOptions with public variables to
hold any needed configuration parameters (a lot of data of type string, a
lot of ints, doubles etc.)
Instead of writing and reading an INi file I use XMLSerialization to read
and write one public static variable of type CMyOptions. this variable is
then used in the code to read and store the configuration.
because XMLSerialization and deserialization is really simple ( both take 4
lines of code, read docs for further info ) you don't have to play with any
XML reading/parsing.
for example (serialization):
XmlSerializer serializer = new XmlSerializer(typeof(CMyOptions));
TextWriter tw = new StreamWriter("options.myini");
serializer.Serialize(tw, myOptionsInstance);
tw.Close();
deserialization:
XmlSerializer serializer = new XmlSerializer(typeof(CMyOptions));
TextReader tr = new StreamReader("options.myini");
CMyOptions myOptionsInstance = (CMyOptions)serializer.Deserialize(tr);
tr.Close();
Viola. This is great, because XMLSerialization stores objects as xml. so you
can edit your configuration manually.
Regards, Wiktor Zychla