MongoDB.Bson.IO.BsonBinaryWriter.WriteJavaScriptWithScope C# (CSharp) Method

WriteJavaScriptWithScope() public method

Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
public WriteJavaScriptWithScope ( string code ) : void
code string The JavaScript code.
return void
        public override void WriteJavaScriptWithScope(string code)
        {
            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
            if (State != BsonWriterState.Value)
            {
                ThrowInvalidState("WriteJavaScriptWithScope", BsonWriterState.Value);
            }

            _buffer.WriteByte((byte)BsonType.JavaScriptWithScope);
            WriteNameHelper();
            _context = new BsonBinaryWriterContext(_context, ContextType.JavaScriptWithScope, _buffer.Position);
            _buffer.WriteInt32(0); // reserve space for size of JavaScript with scope value
            _buffer.WriteString(_binaryWriterSettings.Encoding, code);

            State = BsonWriterState.ScopeDocument;
        }