public override void Serialize( BsonWriter bsonWriter, Type nominalType, object value, bool serializeIdFirst ) { bsonWriter.WriteBoolean((bool) value); }
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(); }
/// <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 cultureInfo = (CultureInfo)value; if (cultureInfo.UseUserOverride) { // the default for UseUserOverride is true so we don't need to serialize it bsonWriter.WriteString(cultureInfo.Name); } else { bsonWriter.WriteStartDocument(); bsonWriter.WriteString("Name", cultureInfo.Name); bsonWriter.WriteBoolean("UseUserOverride", cultureInfo.UseUserOverride); bsonWriter.WriteEndDocument(); } } }
private void SerializeMember(BsonWriter bsonWriter, object obj, BsonMemberMap memberMap) { var value = memberMap.Getter(obj); if (!memberMap.ShouldSerialize(obj, value)) { return; // don't serialize member } bsonWriter.WriteName(memberMap.ElementName); var nominalType = memberMap.MemberType; if (value == null && nominalType.IsInterface) { bsonWriter.WriteNull(); } else if (value == null && memberMap.MemberTypeIsBsonValue) { bsonWriter.WriteStartDocument(); bsonWriter.WriteBoolean("_csharpnull", true); bsonWriter.WriteEndDocument(); } else { var actualType = (value == null) ? nominalType : value.GetType(); var serializer = memberMap.GetSerializer(actualType); serializer.Serialize(bsonWriter, nominalType, value, memberMap.SerializationOptions); } }
/// <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 profileInfo = (SystemProfileInfo)value; bsonWriter.WriteStartDocument(); bsonWriter.WriteDateTime("ts", BsonUtils.ToMillisecondsSinceEpoch(profileInfo.Timestamp)); if (profileInfo.Info != null) { bsonWriter.WriteString("info", profileInfo.Info); } if (profileInfo.Op != null) { bsonWriter.WriteString("op", profileInfo.Op); } if (profileInfo.Namespace != null) { bsonWriter.WriteString("ns", profileInfo.Namespace); } if (profileInfo.Command != null) { bsonWriter.WriteName("command"); profileInfo.Command.WriteTo(bsonWriter); } if (profileInfo.Query != null) { bsonWriter.WriteName("query"); profileInfo.Query.WriteTo(bsonWriter); } if (profileInfo.UpdateObject != null) { bsonWriter.WriteName("updateobj"); profileInfo.UpdateObject.WriteTo(bsonWriter); } if (profileInfo.CursorId != 0) { bsonWriter.WriteInt64("cursorid", profileInfo.CursorId); } if (profileInfo.NumberToReturn != 0) { bsonWriter.WriteInt32("ntoreturn", profileInfo.NumberToReturn); } if (profileInfo.NumberToSkip != 0) { bsonWriter.WriteInt32("ntoskip", profileInfo.NumberToSkip); } if (profileInfo.Exhaust) { bsonWriter.WriteBoolean("exhaust", profileInfo.Exhaust); } if (profileInfo.NumberScanned != 0) { bsonWriter.WriteInt32("nscanned", profileInfo.NumberScanned); } if (profileInfo.IdHack) { bsonWriter.WriteBoolean("idhack", profileInfo.IdHack); } if (profileInfo.ScanAndOrder) { bsonWriter.WriteBoolean("scanAndOrder", profileInfo.ScanAndOrder); } if (profileInfo.Moved) { bsonWriter.WriteBoolean("moved", profileInfo.Moved); } if (profileInfo.FastMod) { bsonWriter.WriteBoolean("fastmod", profileInfo.FastMod); } if (profileInfo.FastModInsert) { bsonWriter.WriteBoolean("fastmodinsert", profileInfo.FastModInsert); } if (profileInfo.Upsert) { bsonWriter.WriteBoolean("upsert", profileInfo.Upsert); } if (profileInfo.KeyUpdates != 0) { bsonWriter.WriteInt32("keyUpdates", profileInfo.KeyUpdates); } if (profileInfo.Exception != null) { bsonWriter.WriteString("exception", profileInfo.Exception); } if (profileInfo.ExceptionCode != 0) { bsonWriter.WriteInt32("exceptionCode", profileInfo.ExceptionCode); } if (profileInfo.NumberReturned != 0) { bsonWriter.WriteInt32("nreturned", profileInfo.NumberReturned); } if (profileInfo.ResponseLength != 0) { bsonWriter.WriteInt32("responseLength", profileInfo.ResponseLength); } bsonWriter.WriteDouble("millis", profileInfo.Duration.TotalMilliseconds); if (profileInfo.Client != null) { bsonWriter.WriteString("client", profileInfo.Client); } if (profileInfo.User != null) { bsonWriter.WriteString("user", profileInfo.User); } if (profileInfo.Error != null) { bsonWriter.WriteString("err", profileInfo.Error); } if (profileInfo.Abbreviated != null) { bsonWriter.WriteString("abbreviated", profileInfo.Abbreviated); } bsonWriter.WriteEndDocument(); } }
public override void Serialize( BsonWriter bsonWriter, Type nominalType, object value, bool serializeIdFirst ) { if (value == null) { bsonWriter.WriteNull(); } else { bsonWriter.WriteBoolean(((BsonBoolean) value).Value); } }
private static void WriteStyleParagraphProperties(BsonWriter bsonWriter, OXmlStyleParagraphProperties element) { if (element.AdjustRightIndent != null) bsonWriter.WriteBoolean("AdjustRightIndent", (bool)element.AdjustRightIndent); if (element.AutoSpaceDE != null) bsonWriter.WriteBoolean("AutoSpaceDE", (bool)element.AutoSpaceDE); if (element.AutoSpaceDN != null) bsonWriter.WriteBoolean("AutoSpaceDN", (bool)element.AutoSpaceDN); if (element.BiDi != null) bsonWriter.WriteBoolean("BiDi", (bool)element.BiDi); if (element.ContextualSpacing != null) bsonWriter.WriteBoolean("ContextualSpacing", (bool)element.ContextualSpacing); if (element.Justification != null) bsonWriter.WriteString("Justification", element.Justification.ToString()); if (element.KeepLines != null) bsonWriter.WriteBoolean("KeepLines", (bool)element.KeepLines); if (element.KeepNext != null) bsonWriter.WriteBoolean("KeepNext", (bool)element.KeepNext); if (element.Kinsoku != null) bsonWriter.WriteBoolean("Kinsoku", (bool)element.Kinsoku); if (element.MirrorIndents != null) bsonWriter.WriteBoolean("MirrorIndents", (bool)element.MirrorIndents); if (element.OutlineLevel != null) bsonWriter.WriteInt32("OutlineLevel", (int)element.OutlineLevel); if (element.OverflowPunctuation != null) bsonWriter.WriteBoolean("OverflowPunctuation", (bool)element.OverflowPunctuation); if (element.PageBreakBefore != null) bsonWriter.WriteBoolean("PageBreakBefore", (bool)element.PageBreakBefore); if (element.SnapToGrid != null) bsonWriter.WriteBoolean("SnapToGrid", (bool)element.SnapToGrid); if (element.SpacingBetweenLines != null) { bsonWriter.WriteStartDocument("SpacingBetweenLines"); WriteSpacingBetweenLines(bsonWriter, element.SpacingBetweenLines); bsonWriter.WriteEndDocument(); } if (element.SuppressAutoHyphens != null) bsonWriter.WriteBoolean("SuppressAutoHyphens", (bool)element.SuppressAutoHyphens); if (element.SuppressLineNumbers != null) bsonWriter.WriteBoolean("SuppressLineNumbers", (bool)element.SuppressLineNumbers); if (element.SuppressOverlap != null) bsonWriter.WriteBoolean("SuppressOverlap", (bool)element.SuppressOverlap); if (element.Tabs != null) { bsonWriter.WriteStartArray("Tabs"); WriteTabs(bsonWriter, element.Tabs); bsonWriter.WriteEndArray(); } if (element.TextAlignment != null) bsonWriter.WriteString("TextAlignment", element.TextAlignment.ToString()); if (element.TextBoxTightWrap != null) bsonWriter.WriteString("TextBoxTightWrap", element.TextBoxTightWrap.ToString()); if (element.TextDirection != null) bsonWriter.WriteString("TextDirection", element.TextDirection.ToString()); if (element.TopLinePunctuation != null) bsonWriter.WriteBoolean("TopLinePunctuation", (bool)element.TopLinePunctuation); if (element.WidowControl != null) bsonWriter.WriteBoolean("WidowControl", (bool)element.WidowControl); if (element.WordWrap != null) bsonWriter.WriteBoolean("WordWrap", (bool)element.WordWrap); }
void IBsonSerializable.Serialize(BsonWriter bsonWriter, Type nominalType, IBsonSerializationOptions options) { bsonWriter.WriteStartDocument(); bsonWriter.WriteDateTime("ts", BsonUtils.ToMillisecondsSinceEpoch(_timestamp)); if (_info != null) { bsonWriter.WriteString("info", _info); } if (_op != null) { bsonWriter.WriteString("op", _op); } if (_namespace != null) { bsonWriter.WriteString("ns", _namespace); } if (_command != null) { bsonWriter.WriteName("command"); _command.WriteTo(bsonWriter); } if (_query != null) { bsonWriter.WriteName("query"); _query.WriteTo(bsonWriter); } if (_updateObject != null) { bsonWriter.WriteName("updateobj"); _updateObject.WriteTo(bsonWriter); } if (_cursorId != 0) { bsonWriter.WriteInt64("cursorid", _cursorId); } if (_numberToReturn != 0) { bsonWriter.WriteInt32("ntoreturn", _numberToReturn); } if (_numberToSkip != 0) { bsonWriter.WriteInt32("ntoskip", _numberToSkip); } if (_exhaust) { bsonWriter.WriteBoolean("exhaust", _exhaust); } if (_numberScanned != 0) { bsonWriter.WriteInt32("nscanned", _numberScanned); } if (_idHack) { bsonWriter.WriteBoolean("idhack", _idHack); } if (_scanAndOrder) { bsonWriter.WriteBoolean("scanAndOrder", _scanAndOrder); } if (_moved) { bsonWriter.WriteBoolean("moved", _moved); } if (_fastMod) { bsonWriter.WriteBoolean("fastmod", _fastMod); } if (_fastModInsert) { bsonWriter.WriteBoolean("fastmodinsert", _fastModInsert); } if (_upsert) { bsonWriter.WriteBoolean("upsert", _upsert); } if (_keyUpdates != 0) { bsonWriter.WriteInt32("keyUpdates", _keyUpdates); } if (_exception != null) { bsonWriter.WriteString("exception", _exception); } if (_exceptionCode != 0) { bsonWriter.WriteInt32("exceptionCode", _exceptionCode); } if (_numberReturned != 0) { bsonWriter.WriteInt32("nreturned", _numberReturned); } if (_responseLength != 0) { bsonWriter.WriteInt32("responseLength", _responseLength); } bsonWriter.WriteDouble("millis", _duration.TotalMilliseconds); if (_client != null) { bsonWriter.WriteString("client", _client); } if (_user != null) { bsonWriter.WriteString("user", _user); } if (_error != null) { bsonWriter.WriteString("err", _error); } if (_abbreviated != null) { bsonWriter.WriteString("abbreviated", _abbreviated); } bsonWriter.WriteEndDocument(); }
private static void SerializePolygon(BsonWriter bsonWriter, OXmlPolygon polygon) { bsonWriter.WriteStartDocument("Polygon"); if (polygon.StartPoint != null) { bsonWriter.WriteInt64("StartPointX", polygon.StartPoint.X); bsonWriter.WriteInt64("StartPointY", polygon.StartPoint.Y); } bsonWriter.WriteStartArray("LinesTo"); foreach (OXmlPoint2DType lineTo in polygon.LinesTo) { bsonWriter.WriteStartDocument(); bsonWriter.WriteInt64("X", lineTo.X); bsonWriter.WriteInt64("Y", lineTo.Y); bsonWriter.WriteEndDocument(); } bsonWriter.WriteEndArray(); if (polygon.Edited != null) bsonWriter.WriteBoolean("Edited", (bool)polygon.Edited); bsonWriter.WriteEndDocument(); }
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options) { if (value == null) throw new PBException("serialize OXmlPictureElement value is null"); if (_trace) pb.Trace.WriteLine("OXmlPictureElementSerializer.Serialize()"); OXmlPictureElement element = (OXmlPictureElement)value; bsonWriter.WriteStartDocument(); bsonWriter.WriteString("Type", "Picture"); bsonWriter.WriteString("File", element.File); if (element.Name != null) bsonWriter.WriteString("Name", element.Name); if (element.Description != null) bsonWriter.WriteString("Description", element.Description); if (element.Width != null) bsonWriter.WriteInt32("Width", (int)element.Width); if (element.Height != null) bsonWriter.WriteInt32("Height", (int)element.Height); if (element.Rotation != 0) bsonWriter.WriteInt32("Rotation", element.Rotation); if (element.HorizontalFlip) bsonWriter.WriteBoolean("HorizontalFlip", element.HorizontalFlip); if (element.VerticalFlip) bsonWriter.WriteBoolean("VerticalFlip", element.VerticalFlip); if (element.CompressionState != A.BlipCompressionValues.Print) bsonWriter.WriteString("CompressionState", element.CompressionState.ToString()); if (element.PresetShape != A.ShapeTypeValues.Rectangle) bsonWriter.WriteString("PresetShape", element.PresetShape.ToString()); //bsonWriter.WriteString("DrawingMode", element.PictureDrawing.DrawingMode.ToString()); bsonWriter.WriteString("DrawingType", element.PictureDrawing.GetDrawingType().ToString()); if (element.PictureDrawing.DrawingMode == OXmlPictureDrawingMode.Anchor) { OXmlAnchorPictureDrawing anchor = (OXmlAnchorPictureDrawing)element.PictureDrawing; //bsonWriter.WriteString("WrapType", anchor.Wrap.WrapType.ToString()); bsonWriter.WriteString("HorizontalRelativeFrom", anchor.HorizontalRelativeFrom.ToString()); if (anchor.HorizontalPositionOffset != null) bsonWriter.WriteInt32("HorizontalPositionOffset", (int)anchor.HorizontalPositionOffset); if (anchor.HorizontalAlignment != null) bsonWriter.WriteString("HorizontalAlignment", anchor.HorizontalAlignment); bsonWriter.WriteString("VerticalRelativeFrom", anchor.VerticalRelativeFrom.ToString()); if (anchor.VerticalPositionOffset != null) bsonWriter.WriteInt32("VerticalPositionOffset", (int)anchor.VerticalPositionOffset); if (anchor.VerticalAlignment != null) bsonWriter.WriteString("VerticalAlignment", anchor.VerticalAlignment); switch (anchor.Wrap.WrapType) { case OXmlAnchorWrapType.WrapSquare: SerializeWrapSquare(bsonWriter, (OXmlAnchorWrapSquare)anchor.Wrap); break; case OXmlAnchorWrapType.WrapTight: SerializeWrapTight(bsonWriter, (OXmlAnchorWrapTight)anchor.Wrap); break; case OXmlAnchorWrapType.WrapTopAndBottom: SerializeWrapTopBottom(bsonWriter, (OXmlAnchorWrapTopAndBottom)anchor.Wrap); break; default: throw new PBException($"WrapType {anchor.Wrap.WrapType} serialize not implemented"); } } bsonWriter.WriteEndDocument(); }
void IBsonSerializable.Serialize( BsonWriter bsonWriter, Type nominalType, IBsonSerializationOptions options ) { bsonWriter.WriteStartDocument(); bsonWriter.WriteDateTime("ts", BsonUtils.ToMillisecondsSinceEpoch(timestamp)); if (info != null) { bsonWriter.WriteString("info", info); } if (op != null) { bsonWriter.WriteString("op", op); } if (@namespace != null) { bsonWriter.WriteString("ns", @namespace); } if (command != null) { bsonWriter.WriteName("command"); command.WriteTo(bsonWriter); } if (query != null) { bsonWriter.WriteName("query"); query.WriteTo(bsonWriter); } if (updateObject != null) { bsonWriter.WriteName("updateobj"); updateObject.WriteTo(bsonWriter); } if (cursorId != 0) { bsonWriter.WriteInt64("cursorid", cursorId); } if (numberToReturn != 0) { bsonWriter.WriteInt32("ntoreturn", numberToReturn); } if (numberToSkip != 0) { bsonWriter.WriteInt32("ntoskip", numberToSkip); } if (exhaust) { bsonWriter.WriteBoolean("exhaust", exhaust); } if (numberScanned != 0) { bsonWriter.WriteInt32("nscanned", numberScanned); } if (idHack) { bsonWriter.WriteBoolean("idhack", idHack); } if (scanAndOrder) { bsonWriter.WriteBoolean("scanAndOrder", scanAndOrder); } if (moved) { bsonWriter.WriteBoolean("moved", moved); } if (fastMod) { bsonWriter.WriteBoolean("fastmod", fastMod); } if (fastModInsert) { bsonWriter.WriteBoolean("fastmodinsert", fastModInsert); } if (upsert) { bsonWriter.WriteBoolean("upsert", upsert); } if (keyUpdates != 0) { bsonWriter.WriteInt32("keyUpdates", keyUpdates); } if (exception != null) { bsonWriter.WriteString("exception", exception); } if (exceptionCode != 0) { bsonWriter.WriteInt32("exceptionCode", exceptionCode); } if (numberReturned != 0) { bsonWriter.WriteInt32("nreturned", numberReturned); } if (responseLength != 0) { bsonWriter.WriteInt32("responseLength", responseLength); } bsonWriter.WriteDouble("millis", duration.TotalMilliseconds); if (client != null) { bsonWriter.WriteString("client", client); } if (user != null) { bsonWriter.WriteString("user", user); } if (error != null) { bsonWriter.WriteString("err", error); } if (abbreviated != null) { bsonWriter.WriteString("abbreviated", abbreviated); } bsonWriter.WriteEndDocument(); }
public override void Serialize( BsonWriter bsonWriter, Type nominalType, object value, bool serializeIdFirst ) { var boolValue = (bool) value; switch (representation) { case BsonType.Boolean: bsonWriter.WriteBoolean(boolValue); break; case BsonType.Double: bsonWriter.WriteDouble(boolValue ? 1.0 : 0.0); break; case BsonType.Int32: bsonWriter.WriteInt32(boolValue ? 1 : 0); break; case BsonType.Int64: bsonWriter.WriteInt64(boolValue ? 1 : 0); break; case BsonType.String: bsonWriter.WriteString(XmlConvert.ToString(boolValue)); break; default: var message = string.Format("'{0}' is not a valid representation for type 'Boolean'", representation); throw new BsonSerializationException(message); } }
private static void WriteStyleRunProperties(BsonWriter bsonWriter, OXmlStyleRunProperties element) { if (element.Bold != null) bsonWriter.WriteBoolean("Bold", (bool)element.Bold); if (element.BoldComplexScript != null) bsonWriter.WriteBoolean("BoldComplexScript", (bool)element.BoldComplexScript); if (element.Caps != null) bsonWriter.WriteBoolean("Caps", (bool)element.Caps); if (element.CharacterScale != null) bsonWriter.WriteInt32("CharacterScale", (int)element.CharacterScale); if (element.DoubleStrike != null) bsonWriter.WriteBoolean("DoubleStrike", (bool)element.DoubleStrike); if (element.Emboss != null) bsonWriter.WriteBoolean("Emboss", (bool)element.Emboss); if (element.Emphasis != null) bsonWriter.WriteString("Emphasis", element.Emphasis.ToString()); if (element.FontSize != null) bsonWriter.WriteString("FontSize", element.FontSize); if (element.FontSizeComplexScript != null) bsonWriter.WriteString("FontSizeComplexScript", element.FontSizeComplexScript); if (element.Imprint != null) bsonWriter.WriteBoolean("Imprint", (bool)element.Imprint); if (element.Italic != null) bsonWriter.WriteBoolean("Italic", (bool)element.Italic); if (element.ItalicComplexScript != null) bsonWriter.WriteBoolean("ItalicComplexScript", (bool)element.ItalicComplexScript); if (element.Kern != null) bsonWriter.WriteInt32("Kern", (int)element.Kern); if (element.NoProof != null) bsonWriter.WriteBoolean("NoProof", (bool)element.NoProof); if (element.Outline != null) bsonWriter.WriteBoolean("Outline", (bool)element.Outline); if (element.Position != null) bsonWriter.WriteString("Position", element.Position); if (element.RunFonts != null) { bsonWriter.WriteStartDocument("RunFonts"); OXmlCommonSerializer.WriteRunFonts(bsonWriter, element.RunFonts); bsonWriter.WriteEndDocument(); } if (element.Shadow != null) bsonWriter.WriteBoolean("Shadow", (bool)element.Shadow); if (element.SmallCaps != null) bsonWriter.WriteBoolean("SmallCaps", (bool)element.SmallCaps); if (element.SnapToGrid != null) bsonWriter.WriteBoolean("SnapToGrid", (bool)element.SnapToGrid); if (element.Spacing != null) bsonWriter.WriteInt32("Spacing", (int)element.Spacing); if (element.SpecVanish != null) bsonWriter.WriteBoolean("SpecVanish", (bool)element.SpecVanish); if (element.Strike != null) bsonWriter.WriteBoolean("Strike", (bool)element.Strike); if (element.TextEffect != null) bsonWriter.WriteString("TextEffect", element.TextEffect.ToString()); if (element.Vanish != null) bsonWriter.WriteBoolean("Vanish", (bool)element.Vanish); if (element.VerticalTextAlignment != null) bsonWriter.WriteString("VerticalTextAlignment", element.VerticalTextAlignment.ToString()); if (element.WebHidden != null) bsonWriter.WriteBoolean("WebHidden", (bool)element.WebHidden); }
private static void WriteSpacingBetweenLines(BsonWriter bsonWriter, OXmlSpacingBetweenLines element) { if (element.After != null) bsonWriter.WriteString("After", element.After); if (element.AfterAutoSpacing != null) bsonWriter.WriteBoolean("AfterAutoSpacing", (bool)element.AfterAutoSpacing); if (element.AfterLines != null) bsonWriter.WriteInt32("AfterLines", (int)element.AfterLines); if (element.Before != null) bsonWriter.WriteString("Before", element.Before); if (element.BeforeAutoSpacing != null) bsonWriter.WriteBoolean("BeforeAutoSpacing", (bool)element.BeforeAutoSpacing); if (element.BeforeLines != null) bsonWriter.WriteInt32("BeforeLines", (int)element.BeforeLines); if (element.Line != null) bsonWriter.WriteString("Line", element.Line); if (element.LineRule != null) bsonWriter.WriteString("LineRule", element.LineRule.ToString()); }
/// <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.WriteStartDocument(); bsonWriter.WriteBoolean("$csharpnull", true); bsonWriter.WriteEndDocument(); } else { bsonWriter.WriteNull(); } }
private static void SerializeSquare(BsonWriter bsonWriter, OXmlSquare square) { bsonWriter.WriteStartDocument("Square"); if (square.StartPoint != null) { bsonWriter.WriteInt64("StartPointX", square.StartPoint.X); bsonWriter.WriteInt64("StartPointY", square.StartPoint.Y); } bsonWriter.WriteInt64("HorizontalSize", square.HorizontalSize); bsonWriter.WriteInt64("VerticalSize", square.VerticalSize); if (square.Edited != null) bsonWriter.WriteBoolean("Edited", (bool)square.Edited); bsonWriter.WriteEndDocument(); }
public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options) { var underlyingValue = value.GetType().GetProperty("Value").GetValue(value, null); var underlyingValueType = nominalType.GetConceptValueType(); if (underlyingValueType == typeof(Guid)) { var guid = (Guid)underlyingValue; var guidAsBytes = guid.ToByteArray (); bsonWriter.WriteBinaryData (guidAsBytes, BsonBinarySubType.UuidLegacy, GuidRepresentation.CSharpLegacy); } else if (underlyingValueType == typeof(double)) bsonWriter.WriteDouble ((double)underlyingValue); else if (underlyingValueType == typeof(float)) bsonWriter.WriteDouble ((double)underlyingValue); else if (underlyingValueType == typeof(Int32)) bsonWriter.WriteInt32 ((Int32)underlyingValue); else if (underlyingValueType == typeof(Int64)) bsonWriter.WriteInt64 ((Int64)underlyingValue); else if (underlyingValueType == typeof(bool)) bsonWriter.WriteBoolean ((bool)underlyingValue); else if (underlyingValueType == typeof(string)) bsonWriter.WriteString ((string)(underlyingValue ?? string.Empty)); else if (underlyingValueType == typeof(decimal)) bsonWriter.WriteString (underlyingValue.ToString()); }
/// <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) { throw new ArgumentNullException("value"); } var bsonBoolean = (BsonBoolean)value; bsonWriter.WriteBoolean(bsonBoolean.Value); }
/// <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) { var boolValue = (bool)value; var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options); switch (representationSerializationOptions.Representation) { case BsonType.Boolean: bsonWriter.WriteBoolean(boolValue); break; case BsonType.Double: bsonWriter.WriteDouble(boolValue ? 1.0 : 0.0); break; case BsonType.Int32: bsonWriter.WriteInt32(boolValue ? 1 : 0); break; case BsonType.Int64: bsonWriter.WriteInt64(boolValue ? 1 : 0); break; case BsonType.String: bsonWriter.WriteString(XmlConvert.ToString(boolValue)); break; default: var message = string.Format("'{0}' is not a valid Boolean representation.", representationSerializationOptions.Representation); throw new BsonSerializationException(message); } }
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options) { if (value == null) throw new PBException("serialize OXmlStyleElement value is null"); if (_trace) pb.Trace.WriteLine("OXmlStyleElementSerializer.Serialize()"); OXmlStyleElement element = (OXmlStyleElement)value; bsonWriter.WriteStartDocument(); bsonWriter.WriteString("Type", "Style"); bsonWriter.WriteString("Id", element.Id); if (element.Name != null) bsonWriter.WriteString("Name", element.Name); bsonWriter.WriteString("StyleType", element.StyleType.ToString()); if (element.Aliases != null) bsonWriter.WriteString("Aliases", element.Aliases); bsonWriter.WriteBoolean("CustomStyle", element.CustomStyle); bsonWriter.WriteBoolean("DefaultStyle", element.DefaultStyle); if (element.Locked != null) bsonWriter.WriteBoolean("Locked", (bool)element.Locked); if (element.SemiHidden != null) bsonWriter.WriteBoolean("SemiHidden", (bool)element.SemiHidden); if (element.StyleHidden != null) bsonWriter.WriteBoolean("StyleHidden", (bool)element.StyleHidden); if (element.UnhideWhenUsed != null) bsonWriter.WriteBoolean("UnhideWhenUsed", (bool)element.UnhideWhenUsed); if (element.UIPriority != null) bsonWriter.WriteInt32("UIPriority", (int)element.UIPriority); if (element.LinkedStyle != null) bsonWriter.WriteString("LinkedStyle", element.LinkedStyle); if (element.BasedOn != null) bsonWriter.WriteString("BasedOn", element.BasedOn); if (element.NextParagraphStyle != null) bsonWriter.WriteString("NextParagraphStyle", element.NextParagraphStyle); if (element.StyleParagraphProperties != null) { bsonWriter.WriteStartDocument("StyleParagraphProperties"); WriteStyleParagraphProperties(bsonWriter, element.StyleParagraphProperties); bsonWriter.WriteEndDocument(); } if (element.StyleRunProperties != null) { bsonWriter.WriteStartDocument("StyleRunProperties"); WriteStyleRunProperties(bsonWriter, element.StyleRunProperties); bsonWriter.WriteEndDocument(); } bsonWriter.WriteEndDocument(); }