1
My problem is this, I need to make a configurable file to integrate to my project, follow its format currently:
PRINTER = 127.0.0.12
PRINTER_PORT = 9100
I’d like to format it for this style:
[PRINTER]
PRINTER = 127.0.0.12
PRINTER_PORT = 9100
Currently I am using the Dictionary method to obtain the data, do you have a better option? Since if you use brackets to highlight the file my function does not read them. Function:
var dic = File.ReadAllLines("config.txt")
.Select(l => l.Split(new[] { '=' }))
.ToDictionary(s => s[0].Trim(), s => s[1].Trim());
VariaveisGlobais.DEFAULT_PRINTER = dic["PRINTER"];
VariaveisGlobais.DEFAULT_PRINTER_PORT = dic["PRINTER_PORT"];
I didn’t even know I had something ready for a parser, it really helped!
– Marcos Barbosa