Пример #1
0
        private void ReadSection()
        {
            while (++_index < _line.Length)
            {
                Char ch = _line[_index];
                if (ch == ']')
                {
                    FlushSection();

                    String sectionName = _sb.ToString().TrimEnd("Section", StringComparison.InvariantCulture);
                    if (_sections.TryGetValue(sectionName, out _currentSectionBinding))
                    {
                        try
                        {
                            _currentSection = _currentSectionBinding.CreateSection();
                            _values         = _currentSection.GetValues().ToDictionary(v => v.Name);
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex, "Failed to load data for the section [{0}]", _currentSection.Name);
                            _values = new Dictionary <String, IniValue>();
                        }
                    }

                    _enabledValue = null;
                    break;
                }
                _sb.Append(ch);
            }
        }
Пример #2
0
        protected IniArray <String> BindStringArray(String name, String[] defaultValue)
        {
            IniArray <String> handler = IniValue.StringArray(name);

            handler.Value = defaultValue;
            _bindings.Add(new ArrayBinding <String>(handler));
            return(handler);
        }
Пример #3
0
        protected IniValue <String> BindString(String name, String defaultValue)
        {
            IniValue <String> handler = IniValue.String(name);

            handler.Value = defaultValue;
            _bindings.Add(new ValueBinding <String>(handler));
            return(handler);
        }
Пример #4
0
        protected IniSet <Int32> BindInt32Set(String name, HashSet <Int32> defaultValue)
        {
            IniSet <Int32> handler = IniValue.Int32Set(name);

            handler.Value = defaultValue;
            _bindings.Add(new SetBinding <Int32>(handler));
            return(handler);
        }
Пример #5
0
        protected IniValue <Int32> BindInt32(String name, Int32 defaultValue)
        {
            IniValue <Int32> handler = IniValue.Int32(name);

            handler.Value = defaultValue;
            _bindings.Add(new ValueBinding <Int32>(handler));
            return(handler);
        }
Пример #6
0
        protected IniValue <Boolean> BindBoolean(String name, Boolean defaultValue)
        {
            IniValue <Boolean> handler = IniValue.Boolean(name);

            handler.Value = defaultValue;
            _bindings.Add(new ValueBinding <Boolean>(handler));
            return(handler);
        }
Пример #7
0
        protected IniValue <String> BindPath(String name, String defaultValue)
        {
            if (IniValue.TryParsePath(defaultValue, out var path))
            {
                defaultValue = path;
            }

            IniValue <String> handler = IniValue.Path(name);

            handler.Value = defaultValue;
            _bindings.Add(new ValueBinding <String>(handler));
            return(handler);
        }
Пример #8
0
        private void ReadPair()
        {
            if (!ReadKey())
            {
                return;
            }

            Boolean escape = false;

            while (++_index < _line.Length)
            {
                Char ch = _line[_index];
                if (escape)
                {
                    if (ch != ';')
                    {
                        break;
                    }

                    _sb.Append(';');
                    escape = false;
                }

                if (ch == ';')
                {
                    escape = true;
                }
                else
                {
                    _sb.Append(ch);
                }
            }

            _currnetValue.ParseValue(_sb.ToString().Trim());

            if (_enabledValue == null && _currnetValue.Name == nameof(IniSection.Enabled))
            {
                _enabledValue = (IniValue <Boolean>)_currnetValue;
            }
        }
Пример #9
0
 protected ValueBinding(IniValue handler)
 {
     Value = handler;
 }
Пример #10
0
 protected IniSection(String name, Boolean isEnabled)
 {
     Name    = name.TrimEnd("Section", StringComparison.InvariantCulture);
     Enabled = BindBoolean(nameof(Enabled), isEnabled);
 }