本文整理汇总了C#中MongoDB.Bson.IO.BsonBinaryWriterContext类的典型用法代码示例。如果您正苦于以下问题:C# BsonBinaryWriterContext类的具体用法?C# BsonBinaryWriterContext怎么用?C# BsonBinaryWriterContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonBinaryWriterContext类属于MongoDB.Bson.IO命名空间,在下文中一共展示了BsonBinaryWriterContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BsonBinaryWriterContext
// constructors
internal BsonBinaryWriterContext(
BsonBinaryWriterContext parentContext,
ContextType contextType,
int startPosition)
{
_parentContext = parentContext;
_contextType = contextType;
_startPosition = startPosition;
}
示例2: BsonBinaryWriterContext
internal BsonBinaryWriterContext(
BsonBinaryWriterContext parentContext,
ContextType contextType,
int startPosition
)
{
this.parentContext = parentContext;
this.contextType = contextType;
this.startPosition = startPosition;
}
示例3: WriteJavaScriptWithScope
/// <summary>
/// Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
/// </summary>
/// <param name="code">The JavaScript code.</param>
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(code);
State = BsonWriterState.ScopeDocument;
}
示例4: WriteJavaScriptWithScope
/// <summary>
/// Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
/// </summary>
/// <param name="code">The JavaScript code.</param>
public override void WriteJavaScriptWithScope(
string code
) {
if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (state != BsonWriterState.Value) {
var message = string.Format("WriteJavaScriptWithScope cannot be called when State is: {0}", state);
throw new InvalidOperationException(message);
}
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(code);
state = BsonWriterState.ScopeDocument;
}
示例5: WriteStartArray
/// <summary>
/// Writes the start of a BSON array to the writer.
/// </summary>
public override void WriteStartArray()
{
if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (State != BsonWriterState.Value)
{
ThrowInvalidState("WriteStartArray", BsonWriterState.Value);
}
_buffer.WriteByte((byte)BsonType.Array);
WriteNameHelper();
_context = new BsonBinaryWriterContext(_context, ContextType.Array, _buffer.Position);
_buffer.WriteInt32(0); // reserve space for size
State = BsonWriterState.Value;
}
示例6: WriteStartArray
/// <summary>
/// Writes the start of a BSON array to the writer.
/// </summary>
public override void WriteStartArray() {
if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (state != BsonWriterState.Value) {
var message = string.Format("WriteStartArray cannot be called when State is: {0}", state);
throw new InvalidOperationException(message);
}
buffer.WriteByte((byte) BsonType.Array);
WriteNameHelper();
context = new BsonBinaryWriterContext(context, ContextType.Array, buffer.Position);
buffer.WriteInt32(0); // reserve space for size
state = BsonWriterState.Value;
}
示例7: WriteStartDocument
/// <summary>
/// Writes the start of a BSON document to the writer.
/// </summary>
public override void WriteStartDocument() {
if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (state != BsonWriterState.Initial && state != BsonWriterState.Value && state != BsonWriterState.ScopeDocument && state != BsonWriterState.Done) {
var message = string.Format("WriteStartDocument cannot be called when State is: {0}", state);
throw new InvalidOperationException(message);
}
if (state == BsonWriterState.Value) {
buffer.WriteByte((byte) BsonType.Document);
WriteNameHelper();
}
var contextType = (state == BsonWriterState.ScopeDocument) ? ContextType.ScopeDocument : ContextType.Document;
context = new BsonBinaryWriterContext(context, ContextType.Document, buffer.Position);
buffer.WriteInt32(0); // reserve space for size
state = BsonWriterState.Name;
}
示例8: WriteStartDocument
/// <summary>
/// Writes the start of a BSON document to the writer.
/// </summary>
public override void WriteStartDocument()
{
if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (State != BsonWriterState.Initial && State != BsonWriterState.Value && State != BsonWriterState.ScopeDocument && State != BsonWriterState.Done)
{
ThrowInvalidState("WriteStartDocument", BsonWriterState.Initial, BsonWriterState.Value, BsonWriterState.ScopeDocument, BsonWriterState.Done);
}
if (State == BsonWriterState.Value)
{
_buffer.WriteByte((byte)BsonType.Document);
WriteNameHelper();
}
var contextType = (State == BsonWriterState.ScopeDocument) ? ContextType.ScopeDocument : ContextType.Document;
_context = new BsonBinaryWriterContext(_context, ContextType.Document, _buffer.Position);
_buffer.WriteInt32(0); // reserve space for size
State = BsonWriterState.Name;
}
示例9: Close
/// <summary>
/// Closes the writer.
/// </summary>
public override void Close() {
// Close can be called on Disposed objects
if (state != BsonWriterState.Closed) {
if (state == BsonWriterState.Done) {
Flush();
}
if (stream != null && settings.CloseOutput) {
stream.Close();
}
context = null;
state = BsonWriterState.Closed;
}
}
示例10: BsonBinaryWriter
/// <summary>
/// Initializes a new instance of the BsonBinaryWriter class.
/// </summary>
/// <param name="buffer">A BsonBuffer.</param>
/// <param name="disposeBuffer">if set to <c>true</c> this BsonBinaryReader will own the buffer and when Dispose is called the buffer will be Disposed also.</param>
/// <param name="settings">Optional BsonBinaryWriter settings.</param>
/// <exception cref="System.ArgumentNullException">
/// encoder
/// or
/// settings
/// </exception>
public BsonBinaryWriter(BsonBuffer buffer, bool disposeBuffer, BsonBinaryWriterSettings settings)
: base(settings)
{
if (buffer == null)
{
throw new ArgumentNullException("encoder");
}
_buffer = buffer;
_disposeBuffer = disposeBuffer;
_binaryWriterSettings = settings; // already frozen by base class
_context = null;
State = BsonWriterState.Initial;
}
示例11: BsonBinaryWriter
/// <summary>
/// Initializes a new instance of the BsonBinaryWriter class.
/// </summary>
/// <param name="stream">A stream.</param>
/// <param name="buffer">A BsonBuffer.</param>
/// <param name="settings">Optional BsonBinaryWriter settings.</param>
public BsonBinaryWriter(
Stream stream,
BsonBuffer buffer,
BsonBinaryWriterSettings settings
) {
this.stream = stream;
if (buffer == null) {
this.buffer = new BsonBuffer();
this.disposeBuffer = true; // only call Dispose if we allocated the buffer
} else {
this.buffer = buffer;
this.disposeBuffer = false;
}
this.settings = settings.Freeze();
context = null;
state = BsonWriterState.Initial;
}
示例12: BsonBinaryWriter
// constructors
/// <summary>
/// Initializes a new instance of the BsonBinaryWriter class.
/// </summary>
/// <param name="stream">A stream.</param>
/// <param name="buffer">A BsonBuffer.</param>
/// <param name="settings">Optional BsonBinaryWriter settings.</param>
public BsonBinaryWriter(Stream stream, BsonBuffer buffer, BsonBinaryWriterSettings settings)
: base(settings)
{
_stream = stream;
if (buffer == null)
{
_buffer = new BsonBuffer();
_disposeBuffer = true; // only call Dispose if we allocated the buffer
}
else
{
_buffer = buffer;
_disposeBuffer = false;
}
_binaryWriterSettings = settings; // already frozen by base class
_context = null;
State = BsonWriterState.Initial;
}
示例13: BsonBinaryWriter
/// <summary>
/// Initializes a new instance of the BsonBinaryWriter class.
/// </summary>
/// <param name="stream">A stream. The BsonBinaryWriter does not own the stream and will not Dispose it.</param>
/// <param name="settings">The BsonBinaryWriter settings.</param>
public BsonBinaryWriter(Stream stream, BsonBinaryWriterSettings settings)
: base(settings)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}
if (!stream.CanSeek)
{
throw new ArgumentException("The stream must be capable of seeking.", "stream");
}
_baseStream = stream;
_bsonStream = (stream as BsonStream) ?? new BsonStreamAdapter(stream);
_settings = settings; // already frozen by base class
_maxDocumentSizeStack.Push(_settings.MaxDocumentSize);
_context = null;
State = BsonWriterState.Initial;
}
示例14: WriteEndArray
/// <summary>
/// Writes the end of a BSON array to the writer.
/// </summary>
public override void WriteEndArray()
{
if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (State != BsonWriterState.Value)
{
ThrowInvalidState("WriteEndArray", BsonWriterState.Value);
}
if (_context.ContextType != ContextType.Array)
{
ThrowInvalidContextType("WriteEndArray", _context.ContextType, ContextType.Array);
}
_buffer.WriteByte(0);
BackpatchSize(); // size of document
_context = _context.ParentContext;
State = GetNextState();
}
示例15: WriteEndDocument
/// <summary>
/// Writes the end of a BSON document to the writer.
/// </summary>
public override void WriteEndDocument()
{
if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (State != BsonWriterState.Name)
{
ThrowInvalidState("WriteEndDocument", BsonWriterState.Name);
}
if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
{
ThrowInvalidContextType("WriteEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
}
_buffer.WriteByte(0);
BackpatchSize(); // size of document
_context = _context.ParentContext;
if (_context == null)
{
State = BsonWriterState.Done;
}
else
{
if (_context.ContextType == ContextType.JavaScriptWithScope)
{
BackpatchSize(); // size of the JavaScript with scope value
_context = _context.ParentContext;
}
State = GetNextState();
}
}