public OXmlParagraphElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options) { OXmlParagraphElement paragraph = new OXmlParagraphElement(); while (true) { BsonType bsonType = bsonReader.ReadBsonType(); if (bsonType == BsonType.EndOfDocument) { break; } //if (bsonType != BsonType.String) // throw new PBException("error ZStringArray cannot contain value of type {0}", bsonType); //var value = bsonReader.ReadString(); string name = bsonReader.ReadName(); switch (name.ToLower()) { case "type": if (bsonType != BsonType.String) { throw new PBException($"wrong type value {bsonType}"); } string type = bsonReader.ReadString(); if (type.ToLower() != "paragraph") { throw new PBException($"invalid Type {type} when deserialize OXmlParagraphElement"); } break; case "style": if (bsonType == BsonType.Null) { break; } if (bsonType != BsonType.String) { throw new PBException($"wrong style value {bsonType}"); } paragraph.Style = bsonReader.ReadString(); break; default: throw new PBException($"unknow Paragraph value \"{name}\""); } } return(paragraph); }
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(); }