Jump to content

c# DotConfparser Class


Guest Mythli

Recommended Posts

public class DotConfParser : Dictionary<String, String>
   {
       public DotConfParser() :base() {}
       public DotConfParser(String FileName)
       {
           this.configFileName = FileName;
           this.Reload();
       }

       public void Reload()
       {
           using (StreamReader streamReader = new StreamReader(File.OpenRead(this.configFileName)))
           {
               while (!streamReader.EndOfStream)
               {
                   Match match = this.searchPattern.Match(streamReader.ReadLine());
                   if (match.Success)
                       if (!base.ContainsKey(match.Groups[2].Value))
                           base.Add(match.Groups[2].Value, match.Groups[3].Value.Trim('"'));
               }
           }
       }
       private String configFileName;
       private Regex searchPattern = new Regex(@"^([ \\\\t]+)?([^#].+)\\\\s*=\\\\s*(?\\\\d)|(?:\\"([^\\"]*)\\")).*$", RegexOptions.Compiled | RegexOptions.Multiline);
   }

A c# class to read mangos configuration files.

Enjoy.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use