Example #1
0
        public IHoconElement Clone(IHoconElement newParent)
        {
            var clone = new HoconArray(newParent);

            clone.AddRange(this);
            return(clone);
        }
Example #2
0
        internal void ResolveValue(HoconSubstitution child)
        {
            var index = IndexOf(child);

            Remove(child);

            if (child.Type != HoconType.Empty)
            {
                if (Type == HoconType.Empty)
                {
                    Type = child.Type;
                }
                else if (!Type.IsMergeable(child.Type))
                {
                    throw HoconParserException.Create(child, child.Path,
                                                      "Invalid substitution, substituted type be must be mergeable with its sibling type. " +
                                                      $"Sibling type:{Type}, substitution type:{child.Type}");
                }

                var clonedValue = (HoconValue)child.ResolvedValue.Clone(Parent);
                switch (Type)
                {
                case HoconType.Object:
                    Insert(index, clonedValue.GetObject());
                    break;

                case HoconType.Array:
                    var hoconArray = new HoconArray(this);
                    hoconArray.AddRange(clonedValue.GetArray());
                    Insert(index, hoconArray);
                    break;

                case HoconType.Boolean:
                case HoconType.Number:
                case HoconType.String:
                    var elementList = new List <IHoconElement>();
                    foreach (var element in clonedValue)
                    {
                        elementList.Add(element);
                    }
                    InsertRange(index, elementList);
                    break;
                }
            }

            switch (Parent)
            {
            case HoconField v:
                v.ResolveValue(this);
                break;

            case HoconArray a:
                a.ResolveValue(child);
                break;

            default:
                throw new Exception($"Invalid parent type while resolving substitution:{Parent.GetType()}");
            }
        }