Example #1
0
        internal HoconValue OlderValueThan(IHoconElement marker)
        {
            var filteredObjectValue = new List <HoconValue>();
            var index = 0;

            while (index < _internalValues.Count)
            {
                var value = _internalValues[index];
                if (value.Any(v => ReferenceEquals(v, marker)))
                {
                    break;
                }

                switch (value.Type)
                {
                case HoconType.Object:
                    filteredObjectValue.Add(value);
                    break;

                case HoconType.Boolean:
                case HoconType.Number:
                case HoconType.String:
                case HoconType.Array:
                    filteredObjectValue.Clear();
                    break;
                }

                index++;
            }

            if (filteredObjectValue.Count == 0)
            {
                return(index == 0 ? null : _internalValues[index - 1]);
            }

            var result = new HoconValue(this);

            foreach (var value in filteredObjectValue)
            {
                result.AddRange(value);
            }

            return(result);
        }