Esempio n. 1
0
        public static RootContext ReadString(string s)
        {
            string[] lines = s.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

            RootContext root = new RootContext();
            Category c = null;

            foreach (string line in lines)
            {
                string thisLine = line.Trim();
                if (thisLine == String.Empty) { continue; }
                string name, value;
                if (ParseCategory(thisLine, out name))
                {
                    c = new Category() { Name = name };
                    root.Categories.Add(c);
                }
                else if (ParseValue(thisLine, out name, out value))
                {
                    Option o = new Option()
                    {
                        Name = name,
                        Value = value,
                        Category = c
                    };
                    if (c != null) { c.Options.Add(o); }
                    else { root.Options.Add(o); }
                }
                else
                {
                    // do some logging here
                }
            }

            return root;
        }
Esempio n. 2
0
 public static string Write(RootContext root)
 {
     string s = "";
     foreach (Option o in root.Options)
     {
         s += FormatOption(o);
     }
     foreach (Category c in root.Categories)
     {
         s += FormatCategory(c);
     }
     return s;
 }