Ejemplo n.º 1
0
        /// <summary>
        /// Writes a BSON regular expression to the writer.
        /// </summary>
        /// <param name="pattern">A regular expression pattern.</param>
        /// <param name="options">A regular expression options.</param>
        public override void WriteRegularExpression(string pattern, string options)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("BsonBinaryWriter");
            }
            if (State != BsonWriterState.Value)
            {
                ThrowInvalidState("WriteRegularExpression", BsonWriterState.Value);
            }

            _buffer.WriteByte((byte)BsonType.RegularExpression);
            WriteNameHelper();
            _buffer.WriteCString(pattern);
            _buffer.WriteCString(options);

            State = GetNextState();
        }
        /// <summary>
        /// Writes a BSON regular expression to the writer.
        /// </summary>
        /// <param name="regex">A BsonRegularExpression.</param>
        public override void WriteRegularExpression(BsonRegularExpression regex)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("BsonBinaryWriter");
            }
            if (State != BsonWriterState.Value)
            {
                ThrowInvalidState("WriteRegularExpression", BsonWriterState.Value);
            }

            _buffer.WriteByte((byte)BsonType.RegularExpression);
            WriteNameHelper();
            _buffer.WriteCString(_binaryWriterSettings.Encoding, regex.Pattern);
            _buffer.WriteCString(_binaryWriterSettings.Encoding, regex.Options);

            State = GetNextState();
        }