private static OXmlPageSize ReadPageSize(BsonReader bsonReader) { bsonReader.ReadStartDocument(); OXmlPageSize value = new OXmlPageSize(); while (true) { BsonType bsonType = bsonReader.ReadBsonType(); if (bsonType == BsonType.EndOfDocument) { break; } string name = bsonReader.ReadName(); switch (name.ToLower()) { case "width": if (bsonType == BsonType.Null) { break; } if (bsonType != BsonType.Int32) { throw new PBException($"wrong PageSize width value {bsonType}"); } value.Width = bsonReader.ReadInt32(); break; case "height": if (bsonType == BsonType.Null) { break; } if (bsonType != BsonType.Int32) { throw new PBException($"wrong PageSize height value {bsonType}"); } value.Height = bsonReader.ReadInt32(); break; default: throw new PBException($"unknow PageSize value \"{name}\""); } } bsonReader.ReadEndDocument(); return(value); }
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options) { if (value == null) { throw new PBException("serialize OXmlDocSectionElement value is null"); } if (_trace) { pb.Trace.WriteLine("OXmlDocSectionElementSerializer.Serialize()"); } OXmlDocSectionElement element = (OXmlDocSectionElement)value; bsonWriter.WriteStartDocument(); bsonWriter.WriteString("Type", "DocSection"); if (element.PageSize != null) { OXmlPageSize pageSize = element.PageSize; bsonWriter.WriteStartDocument("PageSize"); if (pageSize.Width != null) { bsonWriter.WriteInt32("Width", (int)pageSize.Width); } if (pageSize.Height != null) { bsonWriter.WriteInt32("Height", (int)pageSize.Height); } bsonWriter.WriteEndDocument(); } if (element.PageMargin != null) { OXmlPageMargin pageMargin = element.PageMargin; bsonWriter.WriteStartDocument("PageMargin"); if (pageMargin.Top != null) { bsonWriter.WriteInt32("Top", (int)pageMargin.Top); } if (pageMargin.Bottom != null) { bsonWriter.WriteInt32("Bottom", (int)pageMargin.Bottom); } if (pageMargin.Left != null) { bsonWriter.WriteInt32("Left", (int)pageMargin.Left); } if (pageMargin.Right != null) { bsonWriter.WriteInt32("Right", (int)pageMargin.Right); } if (pageMargin.Header != null) { bsonWriter.WriteInt32("Header", (int)pageMargin.Header); } if (pageMargin.Footer != null) { bsonWriter.WriteInt32("Footer", (int)pageMargin.Footer); } bsonWriter.WriteEndDocument(); } if (element.PageNumberStart != null) { bsonWriter.WriteInt32("PageNumberStart", (int)element.PageNumberStart); } bsonWriter.WriteEndDocument(); }