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(); }
public OXmlDocDefaultsRunPropertiesElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options) { OXmlDocDefaultsRunPropertiesElement element = new OXmlDocDefaultsRunPropertiesElement(); while (true) { BsonType bsonType = bsonReader.ReadBsonType(); if (bsonType == BsonType.EndOfDocument) { break; } 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() != "docdefaultsrunproperties") { throw new PBException($"invalid Type {type} when deserialize OXmlDocDefaultsRunPropertiesElement"); } break; case "runfonts": if (bsonType == BsonType.Null) { break; } if (bsonType != BsonType.Document) { throw new PBException($"wrong RunFonts value {bsonType}"); } element.RunFonts = OXmlCommonSerializer.ReadRunFonts(bsonReader); break; case "fontsize": if (bsonType == BsonType.Null) { break; } if (bsonType != BsonType.String) { throw new PBException($"wrong FontSize value {bsonType}"); } element.FontSize = bsonReader.ReadString(); break; default: throw new PBException($"unknow DocDefaultsRunProperties value \"{name}\""); } } return(element); }