コード例 #1
0
        internal void AddToken(BsonToken token)
        {
            if (_parent != null)
            {
                BsonObject bo = _parent as BsonObject;
                if (bo != null)
                {
                    bo.Add(_propertyName, token);
                    _propertyName = null;
                }
                else
                {
                    ((BsonArray)_parent).Add(token);
                }
            }
            else
            {
                if (token.Type != BsonType.Object && token.Type != BsonType.Array)
                {
                    throw ExceptionUtils.CreateJsonWriterException(this, "Error writing {0} value. BSON must start with an Object or Array.".FormatWith(CultureInfo.InvariantCulture, token.Type), null);
                }

                _parent = token;
                _root   = token;
            }
        }
コード例 #2
0
        public override void WriteValue(ulong value)
        {
            if (value > long.MaxValue)
            {
                throw ExceptionUtils.CreateJsonWriterException(this, "Value is too large to fit in a signed 64 bit integer. BSON does not support unsigned values.", null);
            }

            base.WriteValue(value);
            AddValue(value, BsonType.Long);
        }
コード例 #3
0
        /// <summary>
        /// Writes a <see cref="Byte"/>[] value that represents a BSON object id.
        /// </summary>
        /// <param name="value">The Object ID value to write.</param>
        public void WriteObjectId(byte[] value)
        {
            ValidationUtils.ArgumentNotNull(value, nameof(value));

            if (value.Length != 12)
            {
                throw ExceptionUtils.CreateJsonWriterException(this, "An object id must be 12 bytes", null);
            }

            // hack to update the writer state
            SetWriteState(JsonToken.Undefined, null);
            AddValue(value, BsonType.Oid);
        }
コード例 #4
0
 /// <summary>
 /// Writes raw JSON where a value is expected and updates the writer's state.
 /// </summary>
 /// <param name="json">The raw JSON to write.</param>
 public override void WriteRawValue(string json)
 {
     throw ExceptionUtils.CreateJsonWriterException(this, "Cannot write raw JSON as BSON.", null);
 }
コード例 #5
0
 /// <summary>
 /// Writes the start of a constructor with the given name.
 /// </summary>
 /// <param name="name">The name of the constructor.</param>
 public override void WriteStartConstructor(string name)
 {
     throw ExceptionUtils.CreateJsonWriterException(this, "Cannot write JSON constructor as BSON.", null);
 }
コード例 #6
0
 /// <summary>
 /// Writes a comment <c>/*...*/</c> containing the specified text.
 /// </summary>
 /// <param name="text">Text to place inside the comment.</param>
 public override void WriteComment(string text)
 {
     throw ExceptionUtils.CreateJsonWriterException(this, "Cannot write JSON comment as BSON.", null);
 }