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();
        }
        private static OXmlPageMargin ReadPageMargin(BsonReader bsonReader)
        {
            bsonReader.ReadStartDocument();
            OXmlPageMargin value = new OXmlPageMargin();

            while (true)
            {
                BsonType bsonType = bsonReader.ReadBsonType();
                if (bsonType == BsonType.EndOfDocument)
                {
                    break;
                }
                string name = bsonReader.ReadName();
                switch (name.ToLower())
                {
                case "top":
                    if (bsonType == BsonType.Null)
                    {
                        break;
                    }
                    if (bsonType != BsonType.Int32)
                    {
                        throw new PBException($"wrong PageMargin Top value {bsonType}");
                    }
                    value.Top = bsonReader.ReadInt32();
                    break;

                case "bottom":
                    if (bsonType == BsonType.Null)
                    {
                        break;
                    }
                    if (bsonType != BsonType.Int32)
                    {
                        throw new PBException($"wrong PageMargin Bottom value {bsonType}");
                    }
                    value.Bottom = bsonReader.ReadInt32();
                    break;

                case "left":
                    if (bsonType == BsonType.Null)
                    {
                        break;
                    }
                    if (bsonType != BsonType.Int32)
                    {
                        throw new PBException($"wrong PageMargin Left value {bsonType}");
                    }
                    value.Left = bsonReader.ReadInt32();
                    break;

                case "right":
                    if (bsonType == BsonType.Null)
                    {
                        break;
                    }
                    if (bsonType != BsonType.Int32)
                    {
                        throw new PBException($"wrong PageMargin Right value {bsonType}");
                    }
                    value.Right = bsonReader.ReadInt32();
                    break;

                case "header":
                    if (bsonType == BsonType.Null)
                    {
                        break;
                    }
                    if (bsonType != BsonType.Int32)
                    {
                        throw new PBException($"wrong PageMargin Header value {bsonType}");
                    }
                    value.Header = bsonReader.ReadInt32();
                    break;

                case "footer":
                    if (bsonType == BsonType.Null)
                    {
                        break;
                    }
                    if (bsonType != BsonType.Int32)
                    {
                        throw new PBException($"wrong PageMargin Footer value {bsonType}");
                    }
                    value.Footer = bsonReader.ReadInt32();
                    break;

                default:
                    throw new PBException($"unknow PageMargin value \"{name}\"");
                }
            }
            bsonReader.ReadEndDocument();
            return(value);
        }