Example #1
0
        private void LoadIniFile()
        {
            string key;
            string value;

            foreach (string line in GetSection().Split(Environment.NewLine))
            {
                foreach (KeyValuePair <string, string> kvp in line.ToKeyValuePairs())
                {
                    if (!kvp.Key.IsNullOrWhiteSpace())
                    {
                        key   = kvp.Key.Trim();
                        value = kvp.Value.Trim();

                        if (!_keyValues.ContainsKey(key))
                        {
                            _keyValues.Add(key, CleanValue(value));
                        }
                        else
                        {
                            if (!SectionName.IsNullOrWhiteSpace())
                            {
                                throw new ApplicationException("Duplicate '{0}' ini key found in '{1}' section.".FormatString(key, SectionName));
                            }
                            else
                            {
                                throw new ApplicationException("Duplicate '{0}' ini key found in root section.".FormatString(key, SectionName));
                            }
                        }
                    }
                    break;
                }

                //string[] keyValue = line.SplitNTrim("=", ChoStringSplitOptions.None);
                //if (keyValue.Length != 2
                //    || keyValue[0].IsNullOrWhiteSpace()) continue;

                //if (!_keyValues.ContainsKey(keyValue[0]))
                //    _keyValues.Add(keyValue[0], CleanValue(keyValue[1]));
                //else
                //{
                //    if (!SectionName.IsNullOrWhiteSpace())
                //        throw new ApplicationException("Duplicate '{0}' ini key found in '{1}' section.".FormatString(keyValue[0], SectionName));
                //    else
                //        throw new ApplicationException("Duplicate '{0}' ini key found in root section.".FormatString(keyValue[0], SectionName));
                //}
                //_keyValues[keyValue[0]] = CleanValue(keyValue[1]);
            }
        }