NewValue() public method

Creates a fresh list of elements inside this HoconValue and adds the given value to the list.
public NewValue ( IHoconElement value ) : void
value IHoconElement The element to add to the list.
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Parses the object.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="root">if set to <c>true</c> [root].</param>
        private void ParseObject(HoconValue owner, bool root)
        {
            if (owner.IsObject())
            {
                //the value of this KVP is already an object
            }
            else
            {
                //the value of this KVP is not an object, thus, we should add a new
                owner.NewValue(new HoconObject());
            }

            HoconObject currentObject = owner.GetObject();

            while (!reader.EoF)
            {
                Token t = reader.PullNext();
                switch (t.Type)
                {
                    case TokenType.EoF:
                        break;
                    case TokenType.Key:
                        HoconValue value = currentObject.GetOrCreateKey(t.Value);
                        ParseKeyContent(value);
                        if (!root)
                            return;
                        break;

                    case TokenType.ObjectEnd:
                        return;
                }
            }
        }
Ejemplo n.º 2
0
        private void ParseObject(HoconValue owner, bool root, string currentPath)
        {
            if (owner.IsObject())
            {
                //the value of this KVP is already an object
            }
            else
            {
                //the value of this KVP is not an object, thus, we should add a new
                owner.NewValue(new HoconObject());
            }

            HoconObject currentObject = owner.GetObject();

            while (!_reader.EoF)
            {
                Token t = _reader.PullNext();
                switch (t.Type)
                {
                case TokenType.Include:
                    var included      = _includeCallback(t.Value);
                    var substitutions = included.Substitutions;
                    foreach (var substitution in substitutions)
                    {
                        //fixup the substitution, add the current path as a prefix to the substitution path
                        substitution.Path = currentPath + "." + substitution.Path;
                    }
                    _substitutions.AddRange(substitutions);
                    var otherObj = included.Value.GetObject();
                    owner.GetObject().Merge(otherObj);

                    break;

                case TokenType.EoF:
                    break;

                case TokenType.Key:
                    HoconValue value    = currentObject.GetOrCreateKey(t.Value);
                    var        nextPath = currentPath == "" ? t.Value : currentPath + "." + t.Value;
                    ParseKeyContent(value, nextPath);
                    if (!root)
                    {
                        return;
                    }
                    break;

                case TokenType.ObjectEnd:
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        private void ParseObject(HoconValue owner, bool root,string currentPath)
        {
            if (owner.IsObject())
            {
                //the value of this KVP is already an object
            }
            else
            {
                //the value of this KVP is not an object, thus, we should add a new
                owner.NewValue(new HoconObject());
            }

            HoconObject currentObject = owner.GetObject();

            while (!_reader.EoF)
            {
                Token t = _reader.PullNext();
                switch (t.Type)
                {
                    case TokenType.Include:
                        var included = _includeCallback(t.Value);
                        var substitutions = included.Substitutions;
                        foreach (var substitution in substitutions)
                        {
                            //fixup the substitution, add the current path as a prefix to the substitution path
                            substitution.Path = currentPath + "." + substitution.Path;
                        }
                        _substitutions.AddRange(substitutions);
                        var otherObj = included.Value.GetObject();
                        owner.GetObject().Merge(otherObj);

                        break;
                    case TokenType.EoF:
                        break;
                    case TokenType.Key:
                        HoconValue value = currentObject.GetOrCreateKey(t.Value);
                        var nextPath = currentPath == "" ? t.Value : currentPath + "." + t.Value;
                        ParseKeyContent(value, nextPath);
                        if (!root)
                            return;
                        break;

                    case TokenType.ObjectEnd:
                        return;
                }
            }
        }
Ejemplo n.º 4
0
        private void ParseObject(HoconValue owner, bool root)
        {
            if (owner.IsObject())
            {
                //the value of this KVP is already an object
            }
            else
            {
                //the value of this KVP is not an object, thus, we should add a new
                owner.NewValue(new HoconObject());
            }

            HoconObject currentObject = owner.GetObject();

            while (!reader.EoF)
            {
                Token t = reader.PullNext();
                switch (t.Type)
                {
                case TokenType.EoF:
                    break;

                case TokenType.Key:
                    HoconValue value = currentObject.GetOrCreateKey(t.Value);
                    ParseKeyContent(value);
                    if (!root)
                    {
                        return;
                    }
                    break;

                case TokenType.ObjectEnd:
                    return;
                }
            }
        }
Ejemplo n.º 5
0
        private void ParseObject(HoconValue owner, bool root,string currentPath)
        {
            try
            {
                PushDiagnostics("{");

                if (owner.IsObject())
                {
                    //the value of this KVP is already an object
                }
                else
                {
                    //the value of this KVP is not an object, thus, we should add a new
                    owner.NewValue(new HoconObject());
                }

                HoconObject currentObject = owner.GetObject();

                while (!_reader.EoF)
                {
                    Token t = _reader.PullNext();
                    switch (t.Type)
                    {
                        case TokenType.Include:
                            var included = _includeCallback(t.Value);
                            var substitutions = included.Substitutions;
                            foreach (var substitution in substitutions)
                            {
                                //fixup the substitution, add the current path as a prefix to the substitution path
                                substitution.Path = currentPath + "." + substitution.Path;
                            }
                            _substitutions.AddRange(substitutions);
                            var otherObj = included.Value.GetObject();
                            owner.GetObject().Merge(otherObj);

                            break;
                        case TokenType.EoF:
                            if (!string.IsNullOrEmpty(currentPath))
                            {
                                throw new HoconParserException(string.Format("Expected end of object but found EoF {0}",GetDiagnosticsStackTrace()));
                            }
                            break;
                        case TokenType.Key:
                            HoconValue value = currentObject.GetOrCreateKey(t.Value);
                            var nextPath = currentPath == "" ? t.Value : currentPath + "." + t.Value;
                            ParseKeyContent(value, nextPath);
                            if (!root)
                                return;
                            break;

                        case TokenType.ObjectEnd:
                            return;
                    }
                }
            }
            finally
            {
                PopDiagnostics();
            }
        }
Ejemplo n.º 6
0
        private void ParseObject(HoconValue owner, bool root, string currentPath)
        {
            try
            {
                PushDiagnostics("{");

                if (owner.IsObject())
                {
                    //the value of this KVP is already an object
                }
                else
                {
                    //the value of this KVP is not an object, thus, we should add a new
                    owner.NewValue(new HoconObject());
                }

                HoconObject currentObject = owner.GetObject();

                while (!_reader.EoF)
                {
                    Token t = _reader.PullNext();
                    switch (t.Type)
                    {
                    case TokenType.Include:
                        var included      = _includeCallback(t.Value);
                        var substitutions = included.Substitutions;
                        foreach (var substitution in substitutions)
                        {
                            //fixup the substitution, add the current path as a prefix to the substitution path
                            substitution.Path = currentPath + "." + substitution.Path;
                        }
                        _substitutions.AddRange(substitutions);
                        var otherObj = included.Value.GetObject();
                        owner.GetObject().Merge(otherObj);

                        break;

                    case TokenType.EoF:
                        if (!string.IsNullOrEmpty(currentPath))
                        {
                            throw new HoconParserException(string.Format("Expected end of object but found EoF {0}", GetDiagnosticsStackTrace()));
                        }
                        break;

                    case TokenType.Key:
                        HoconValue value    = currentObject.GetOrCreateKey(t.Value);
                        var        nextPath = currentPath == "" ? t.Value : currentPath + "." + t.Value;
                        ParseKeyContent(value, nextPath);
                        if (!root)
                        {
                            return;
                        }
                        break;

                    case TokenType.ObjectEnd:
                        return;
                    }
                }
            }
            finally
            {
                PopDiagnostics();
            }
        }