Newtonsoft.Json.Bson.BsonWriter.AddToken C# (CSharp) Method

AddToken() private method

private AddToken ( Newtonsoft.Json.Bson.BsonToken token ) : void
token Newtonsoft.Json.Bson.BsonToken
return void
        internal void AddToken(BsonToken token)
        {
            if (_parent != null)
            {
                if (_parent is BsonObject)
                {
                    ((BsonObject)_parent).Add(_propertyName, token);
                    _propertyName = null;
                }
                else
                {
                    ((BsonArray)_parent).Add(token);
                }
            }
            else
            {
                if (token.Type != BsonType.Object && token.Type != BsonType.Array)
                {
                    throw JsonWriterException.Create(this, "Error writing {0} value. BSON must start with an Object or Array.".FormatWith(CultureInfo.InvariantCulture, token.Type), null);
                }

                _parent = token;
                _root = token;
            }
        }