本文整理汇总了C#中MongoDB.Bson.IO.BsonWriter.WriteStartDocument方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteStartDocument方法的具体用法?C# BsonWriter.WriteStartDocument怎么用?C# BsonWriter.WriteStartDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.WriteStartDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
IDictionary<string, object> obj = value as IDictionary<string, object>;
if (obj == null)
{
bsonWriter.WriteNull();
return;
}
bsonWriter.WriteStartDocument();
foreach (var member in obj)
{
bsonWriter.WriteName(member.Key);
object memberValue = member.Value;
if (memberValue == null)
{
bsonWriter.WriteNull();
}
else
{
nominalType = memberValue.GetType();
var serializer = BsonSerializer.LookupSerializer(nominalType);
serializer.Serialize(bsonWriter, nominalType, memberValue, options);
}
}
bsonWriter.WriteEndDocument();
}
示例2: 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);
}
}
示例3: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: 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
示例7: 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();
}
示例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 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();
}
示例10: 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();
}
示例11: 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();
}
示例12: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
throw new PBException("serialize OXmlTextElement value is null");
if (_trace)
pb.Trace.WriteLine("OXmlTextElementSerializer.Serialize()");
OXmlTextElement element = (OXmlTextElement)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("Type", "Text");
if (element.Text != null)
bsonWriter.WriteString("Text", element.Text);
if (element.PreserveSpace)
bsonWriter.WriteBoolean("PreserveSpace", element.PreserveSpace);
bsonWriter.WriteEndDocument();
}
示例13: 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();
}
示例14: 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();
}
示例15: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
throw new PBException("serialize OXmlDocDefaultsRunPropertiesElement value is null");
if (_trace)
pb.Trace.WriteLine("OXmlRunPropertiesDefaultElementSerializer.Serialize()");
OXmlDocDefaultsRunPropertiesElement element = (OXmlDocDefaultsRunPropertiesElement)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("Type", "DocDefaultsRunProperties");
if (element.RunFonts != null)
{
bsonWriter.WriteStartDocument("RunFonts");
OXmlCommonSerializer.WriteRunFonts(bsonWriter, element.RunFonts);
bsonWriter.WriteEndDocument();
}
if (element.FontSize != null)
bsonWriter.WriteString("FontSize", element.FontSize);
bsonWriter.WriteEndDocument();
}