public void Load(String file)
        {
            String[] lines = File.ReadAllLines(file);
            foreach (String line in lines)
            {
                PropertyFileLine pfLine = null;
                if (this.FileType == Type.Java)
                {
                    pfLine = ParseJava(line);
                }
                else if (this.FileType == Type.Ini)
                {
                    pfLine = ParseIni(line);
                }

                if (pfLine != null)
                {
                    _lines.Add(pfLine);
                    int lineNumber = _lines.Count - 1;
                    if (pfLine.IsSection)
                    {
                        AddToSections(pfLine.Section, lineNumber);
                    }
                    else if (!(pfLine.IsNotAValidProperty))
                    {
                        AddToIndex(pfLine.Section, pfLine.Key, lineNumber);
                    }
                }
            }
        }
        public void SetProperty(String section, String key, String value)
        {
            PropertyFileLine line = GetProperty(section, key);

            if (line != null)
            {
                line.Value = value;
                line.UpdateRawLine();
            }
        }
        private PropertyFileLine ParseIni(String line)
        {
            PropertyFileLine pfLine = new PropertyFileLine();

            pfLine.RawLine = line;

            if (String.IsNullOrWhiteSpace(line))
            {
                pfLine.IsNotAValidProperty = true;
            }
            else if (line.Trim().StartsWith(";") || line.Trim().StartsWith("#"))
            {
                pfLine.IsNotAValidProperty = true;
                pfLine.Comment             = line;
            }
            else if (line.Trim().StartsWith("["))
            {
                Regex getSection = new Regex(@"^(\s*)\[(.*)\]\s*$");
                Match match      = getSection.Match(line);
                pfLine.LeadingSpace = match.Groups[1].Value;
                pfLine.Section      = match.Groups[2].Value;
                pfLine.IsSection    = true;
                _currentSection     = match.Groups[2].Value;
            }
            else
            {
                Regex  getKeyValue = new Regex(@"^(\s*)(.*?)(\s*[=|:]\s*)(.*)$");
                String matchLine   = line.Replace(@"\=", @"\~");    // Replace Any Escaped Equal Signs So Regex Will Not Match Them
                matchLine = matchLine.Replace(@"\:", @"\`");        // Replace Any Escaped Colon Signs So Regex Will Not Match Them
                Match match = getKeyValue.Match(matchLine);
                pfLine.LeadingSpace = match.Groups[1].Value;
                pfLine.Section      = _currentSection;
                pfLine.Key          = match.Groups[2].Value;
                pfLine.Operator     = match.Groups[3].Value;
                pfLine.Value        = match.Groups[4].Value;

                if (!String.IsNullOrWhiteSpace(pfLine.Key))
                {
                    pfLine.Key = pfLine.Key.Replace(@"\~", @"\=");      // Replace Previously Escaped Equal Signs With Original Value
                    pfLine.Key = pfLine.Key.Replace(@"\`", @"\:");      // Replace Previously Escaped Equal Signs With Original Value
                }

                if (!String.IsNullOrWhiteSpace(pfLine.Value))
                {
                    pfLine.Value = pfLine.Value.Replace(@"\~", @"\=");  // Replace Previously Escaped Equal Signs With Original Value
                    pfLine.Value = pfLine.Value.Replace(@"\`", @"\:");  // Replace Previously Escaped Equal Signs With Original Value
                }
            }

            return(pfLine);
        }
        private PropertyFileLine ParseJava(String line)
        {
            PropertyFileLine pfLine = new PropertyFileLine();

            pfLine.RawLine = line;

            if (String.IsNullOrWhiteSpace(line))
            {
                pfLine.IsNotAValidProperty = true;
            }
            else if (line.Trim().StartsWith("#") || line.Trim().StartsWith(";"))
            {
                pfLine.IsNotAValidProperty = true;
                pfLine.Comment             = line;
            }
            else
            {
//                Regex getKeyValue = new Regex(@"^(\s*)(\S*?)(\s*[=|:]\s*)(.*)$");     // Relaxed Standards Around "No Spaces In Key" for Endur OpenLink Config Files
                Regex  getKeyValue = new Regex(@"^(\s*)(.*?)(\s*[=|:]\s*)(.*)$");
                String matchLine   = line.Replace(@"\=", @"\~");    // Replace Any Escaped Equal Signs So Regex Will Not Match Them
                matchLine = matchLine.Replace(@"\:", @"\`");        // Replace Any Escaped Colon Signs So Regex Will Not Match Them
                Match match = getKeyValue.Match(matchLine);
                if (match.Success)
                {
                    pfLine.LeadingSpace = match.Groups[1].Value;
                    pfLine.Key          = match.Groups[2].Value;
                    pfLine.Operator     = match.Groups[3].Value;
                    pfLine.Value        = match.Groups[4].Value;

                    if (!String.IsNullOrWhiteSpace(pfLine.Key))
                    {
                        pfLine.Key = pfLine.Key.Replace(@"\~", @"\=");      // Replace Previously Escaped Equal Signs With Original Value
                        pfLine.Key = pfLine.Key.Replace(@"\`", @"\:");      // Replace Previously Escaped Equal Signs With Original Value
                    }

                    if (!String.IsNullOrWhiteSpace(pfLine.Value))
                    {
                        pfLine.Value = pfLine.Value.Replace(@"\~", @"\=");  // Replace Previously Escaped Equal Signs With Original Value
                        pfLine.Value = pfLine.Value.Replace(@"\`", @"\:");  // Replace Previously Escaped Equal Signs With Original Value
                    }
                }
                else
                {
                    pfLine.IsNotAValidProperty = true;
                }
            }

            return(pfLine);
        }
        public void AddProperty(String section, String key, String value)
        {
            AddSection(section);

            PropertyFileLine line = new PropertyFileLine();
            int insertAt          = GetNextLineIndex(section);

            line.Section  = section;
            line.Key      = key;
            line.Value    = value;
            line.Operator = @"=";
            line.UpdateRawLine();

            _lines.Insert(insertAt, line);
            AddToIndex(section, key, insertAt);
            RebuildIndexes(insertAt);
        }
        public void AddSection(String section)
        {
            if (!String.IsNullOrWhiteSpace(section) && (this.FileType == Type.Ini))
            {
                if (!_sections.ContainsKey(section))
                {
                    PropertyFileLine line = new PropertyFileLine();
                    int insertAt          = GetNextLineIndex(section);
                    line.Section = section;
                    line.RawLine = "[" + section + "]";

                    _lines.Insert(insertAt, line);
                    _sections.Add(section, insertAt);
                    RebuildIndexes(insertAt);
                }
            }
        }