本文整理汇总了C#中MongoDB.Bson.IO.BsonWriter.WriteEndDocument方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteEndDocument方法的具体用法?C# BsonWriter.WriteEndDocument怎么用?C# BsonWriter.WriteEndDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.WriteEndDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options) {
var dateTimeOffset = (DateTimeOffset)value;
var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);
switch (representationSerializationOptions.Representation) {
case BsonType.Array:
bsonWriter.WriteStartArray();
bsonWriter.WriteInt64(dateTimeOffset.UtcTicks);
bsonWriter.WriteInt32((int)dateTimeOffset.Offset.TotalMinutes);
bsonWriter.WriteEndArray();
break;
case BsonType.Document:
bsonWriter.WriteStartDocument();
bsonWriter.WriteDateTime("DateTime", BsonUtils.ToMillisecondsSinceEpoch(dateTimeOffset.UtcDateTime));
bsonWriter.WriteInt64("Ticks", dateTimeOffset.UtcTicks);
bsonWriter.WriteInt32("Offset", (int)dateTimeOffset.Offset.TotalMinutes);
bsonWriter.WriteEndDocument();
break;
default:
var message = string.Format("'{0}' is not a valid DateTimeOffset representation.", representationSerializationOptions.Representation);
throw new BsonSerializationException(message);
}
}
示例2: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
return;
}
var metaObject = ((IDynamicMetaObjectProvider)value).GetMetaObject(Expression.Constant(value));
var memberNames = metaObject.GetDynamicMemberNames().ToList();
if (memberNames.Count == 0)
{
bsonWriter.WriteNull();
return;
}
bsonWriter.WriteStartDocument();
foreach (var memberName in memberNames)
{
bsonWriter.WriteName(memberName);
var memberValue = BinderHelper.GetMemberValue(value, memberName);
if (memberValue == null)
bsonWriter.WriteNull();
else
{
var memberType = memberValue.GetType();
var serializer = BsonSerializer.LookupSerializer(memberType);
serializer.Serialize(bsonWriter, memberType, memberValue, options);
}
}
bsonWriter.WriteEndDocument();
}
示例3: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
var c = (C)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("nominalType", nominalType.Name);
bsonWriter.WriteInt32("X", c.X);
bsonWriter.WriteEndDocument();
}
示例4: Serialize
public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
var timeOfDay = (TimeOfDay)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteInt32("Hour", timeOfDay.Hour);
bsonWriter.WriteInt32("Minute", timeOfDay.Minute);
bsonWriter.WriteInt32("Second", timeOfDay.Second);
bsonWriter.WriteEndDocument();
}
示例5: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
var crs = (GeoJsonNamedCoordinateReferenceSystem)value;
bsonWriter.WriteStartDocument();
SerializeType(bsonWriter, crs.Type);
bsonWriter.WriteStartDocument("properties");
bsonWriter.WriteString("name", crs.Name);
bsonWriter.WriteEndDocument();
bsonWriter.WriteEndDocument();
}
}
开发者ID:pwelter34,项目名称:mongo-csharp-driver,代码行数:18,代码来源:GeoJsonNamedCoordinateReferenceSystemSerializer.cs
示例6: Serialize
public override void Serialize(BsonWriter bsonWriter, System.Type nominalType, object value, IBsonSerializationOptions options)
{
var rectangle = (Rectangle) value;
bsonWriter.WriteStartDocument();
WriteVector(bsonWriter,"Min",rectangle.Min);
WriteVector(bsonWriter,"Max",rectangle.Max);
bsonWriter.WriteDouble("Width",rectangle.Width);
bsonWriter.WriteDouble("Height",rectangle.Height);
bsonWriter.WriteEndDocument();
}
示例7: Serialize
public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
var method = (MethodInfo)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteName("Type");
bsonWriter.WriteString(method.DeclaringType.AssemblyQualifiedName);
bsonWriter.WriteName("Method");
bsonWriter.WriteString(GetMethodSignature(method));
bsonWriter.WriteEndDocument();
}
示例8: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
throw new PBException("serialize OXmlSimpleFieldElement value is null");
if (_trace)
pb.Trace.WriteLine("OXmlSimpleFieldElementSerializer.Serialize()");
OXmlSimpleFieldElement element = (OXmlSimpleFieldElement)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("Type", "SimpleField");
bsonWriter.WriteString("Instruction", element.Instruction);
bsonWriter.WriteEndDocument();
}
示例9: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
throw new PBException("serialize OXmlOpenHeader value is null");
if (_trace)
pb.Trace.WriteLine("OXmlOpenHeaderElementSerializer.Serialize()");
OXmlOpenHeaderElement element = (OXmlOpenHeaderElement)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("Type", "OpenHeader");
bsonWriter.WriteString("HeaderType", element.HeaderType.ToString());
bsonWriter.WriteEndDocument();
}
示例10: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
throw new PBException("serialize OXmlParagraphElement value is null");
if (_trace)
pb.Trace.WriteLine("OXmlParagraphElementSerializer.Serialize()");
OXmlParagraphElement paragraph = (OXmlParagraphElement)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("Type", "Paragraph");
if (paragraph.Style != null)
bsonWriter.WriteString("Style", paragraph.Style);
bsonWriter.WriteEndDocument();
}
示例11: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options
)
{
var nvc = (NameValueCollection)value;
bsonWriter.WriteStartDocument();
if (nvc != null && nvc.Count > 0)
{
foreach (var key in nvc.AllKeys)
{
bsonWriter.WriteString(key.Replace(".", "__period__"), nvc[key]);
}
}
bsonWriter.WriteEndDocument();
}
示例12: Serialize
public override void Serialize( BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options )
{
var dictionary = (DynamicDictionary)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteString( "_t", "DynamicDictionary" );
if( dictionary != null )
{
foreach( var entry in dictionary )
{
bsonWriter.WriteName( entry.Key.Replace( '.', '\x03' ) );
BsonSerializer.Serialize( bsonWriter, typeof( object ), entry.Value );
}
}
bsonWriter.WriteEndDocument();
}
示例13: Serialize
/// <summary>
/// Serializes an object of type System.Drawing.Size to a BsonWriter.
/// </summary>
/// <param name="bsonWriter">The BsonWriter.</param>
/// <param name="nominalType">The nominal type.</param>
/// <param name="value">The object.</param>
/// <param name="options">The serialization options.</param>
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options)
{
var size = (System.Drawing.Size)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteInt32("Width", size.Width);
bsonWriter.WriteInt32("Height", size.Height);
bsonWriter.WriteEndDocument();
}
示例14: Serialize
/// <summary>
/// Serializes an object to a BsonWriter.
/// </summary>
/// <param name="bsonWriter">The BsonWriter.</param>
/// <param name="nominalType">The nominal type.</param>
/// <param name="value">The object.</param>
/// <param name="options">The serialization options.</param>
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
var actualType = value.GetType();
var discriminator = GetDiscriminator(nominalType, actualType);
if (discriminator != null)
{
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("_t", discriminator);
bsonWriter.WriteName("_v");
Serialize(bsonWriter, actualType, value, options);
bsonWriter.WriteEndDocument();
return;
}
var arraySerializationOptions = EnsureSerializationOptions<ArraySerializationOptions>(options);
var itemSerializationOptions = arraySerializationOptions.ItemSerializationOptions;
Type lastItemType = null;
IBsonSerializer lastItemSerializer = null;
bsonWriter.WriteStartArray();
foreach (var item in EnumerateItemsInSerializationOrder(value))
{
var itemType = (item == null) ? typeof(object) : item.GetType();
IBsonSerializer itemSerializer;
if (itemType == lastItemType)
{
itemSerializer = lastItemSerializer;
}
else
{
itemSerializer = BsonSerializer.LookupSerializer(itemType);
lastItemType = itemType;
lastItemSerializer = itemSerializer;
}
itemSerializer.Serialize(bsonWriter, typeof(object), item, itemSerializationOptions);
}
bsonWriter.WriteEndArray();
}
}
示例15: Serialize
/// <summary>
/// Serializes a Bitmap to a BsonWriter.
/// </summary>
/// <param name="bsonWriter">The BsonWriter.</param>
/// <param name="nominalType">The nominal type.</param>
/// <param name="value">The Bitmap.</param>
/// <param name="options">The serialization options.</param>
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options)
{
if (nominalType != typeof(Image) && nominalType != typeof(Bitmap))
{
var message = string.Format("Nominal type must be Image or Bitmap, not {0}.", nominalType.FullName);
throw new ArgumentException(message, "nominalType");
}
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
var actualType = value.GetType();
if (actualType != typeof(Bitmap))
{
var message = string.Format("Actual type must be Bitmap, not {0}.", actualType.FullName);
throw new ArgumentException(message, "actualType");
}
var bitmap = (Bitmap)value;
var stream = new MemoryStream();
bitmap.Save(stream, ImageFormat.Bmp);
var bytes = stream.ToArray();
if (nominalType == typeof(Image))
{
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("_t", "Bitmap");
bsonWriter.WriteBinaryData("bitmap", bytes, BsonBinarySubType.Binary);
bsonWriter.WriteEndDocument();
}
else
{
bsonWriter.WriteBinaryData(bytes, BsonBinarySubType.Binary);
}
}
}