miércoles, 17 de agosto de 2011

Config file for application in C#

//Application Global Variables
int app_owner = 0;
Dictionary() operators;

...

operators = new Dictionary();

using (StreamReader str = new StreamReader(@"app.cfg"))
{
string strline;
strline = str.ReadLine();
string value = "";

while (!str.EndOfStream)
{
while (strline != "[END]")
{
if (strline.StartsWith("["))
{
value = strline;
}
else
{
operators.Add(int.Parse(strline), value);
if (value.IndexOf("*") > 0)
owner = int.Parse(strline);
}

strline = str.ReadLine();
}
}

...

//file content: app.cfg

[JOHN]
1 -------------(#) IS THE ID FOR JOHN
[THOMAS]* ------(*) MARK FOR THE OWNER OR ADMINISTRATOR
2
[END] ---------- MARK FOR THE END