示例#1
0
        public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            object value = null;
            var valueType = actualType.GetConceptValueType();
			if (valueType == typeof(Guid)) {
				var guidBytes = new byte[16];
				BsonBinarySubType subType;
				bsonReader.ReadBinaryData (out guidBytes, out subType);
				value = new Guid (guidBytes);
			} else if (valueType == typeof(double))
				value = bsonReader.ReadDouble ();
			else if (valueType == typeof(float))
				value = (float)bsonReader.ReadDouble ();
			else if (valueType == typeof(Int32))
				value = bsonReader.ReadInt32 ();
			else if (valueType == typeof(Int64))
				value = bsonReader.ReadInt64 ();
			else if (valueType == typeof(bool))
				value = bsonReader.ReadBoolean ();
			else if (valueType == typeof(string))
				value = bsonReader.ReadString ();
			else if (valueType == typeof(decimal))
				value = decimal.Parse (bsonReader.ReadString ());
            
            var concept = ConceptFactory.CreateConceptInstance(actualType, value);
            return concept;
        }
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(bool));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Boolean:
                    return bsonReader.ReadBoolean();
                case BsonType.Double:
                    return bsonReader.ReadDouble() != 0.0;
                case BsonType.Int32:
                    return bsonReader.ReadInt32() != 0;
                case BsonType.Int64:
                    return bsonReader.ReadInt64() != 0;
                case BsonType.Null:
                    bsonReader.ReadNull();
                    return false;
                case BsonType.String:
                    return XmlConvert.ToBoolean(bsonReader.ReadString().ToLower());
                default:
                    var message = string.Format("Cannot deserialize Boolean from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(CultureInfo));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Null:
                    bsonReader.ReadNull();
                    return null;
                case BsonType.Document:
                    bsonReader.ReadStartDocument();
                    var name = bsonReader.ReadString("Name");
                    var useUserOverride = bsonReader.ReadBoolean("UseUserOverride");
                    bsonReader.ReadEndDocument();
                    return new CultureInfo(name, useUserOverride);
                case BsonType.String:
                    return new CultureInfo(bsonReader.ReadString());
                default:
                    var message = string.Format("Cannot deserialize CultureInfo from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     return bsonReader.ReadBoolean();
 }
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(BsonNull));

            var bsonType = bsonReader.GetCurrentBsonType();
            string message;
            switch (bsonType)
            {
                case BsonType.Null:
                    bsonReader.ReadNull();
                    return BsonNull.Value;
                case BsonType.Document:
                    bsonReader.ReadStartDocument();
                    var name = bsonReader.ReadName();
                    if (name == "_csharpnull" || name == "$csharpnull")
                    {
                        var csharpNull = bsonReader.ReadBoolean();
                        bsonReader.ReadEndDocument();
                        return csharpNull ? null : BsonNull.Value;
                    }
                    else
                    {
                        message = string.Format("Unexpected element name while deserializing a BsonNull: {0}.", name);
                        throw new FileFormatException(message);
                    }
                default:
                    message = string.Format("Cannot deserialize BsonNull from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(BsonBoolean));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Boolean:
                    return (BsonBoolean)bsonReader.ReadBoolean();
                default:
                    var message = string.Format("Cannot deserialize BsonBoolean from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
 public OXmlTextElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
 {
     OXmlTextElement element = new OXmlTextElement();
     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() != "text")
                     throw new PBException($"invalid Type {type} when deserialize OXmlTextElement");
                 break;
             case "text":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong text value {bsonType}");
                 element.Text = bsonReader.ReadString();
                 break;
             case "preservespace":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong PreserveSpace value {bsonType}");
                 element.PreserveSpace = bsonReader.ReadBoolean();
                 break;
             default:
                 throw new PBException($"unknow Text value \"{name}\"");
         }
     }
     return element;
 }
 /// <summary>
 /// Deserializes an object from a BsonReader.
 /// </summary>
 /// <param name="bsonReader">The BsonReader.</param>
 /// <param name="nominalType">The nominal type of the object.</param>
 /// <param name="options">The serialization options.</param>
 /// <returns>An object.</returns>
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType,
     IBsonSerializationOptions options
 ) {
     var bsonType = bsonReader.CurrentBsonType;
     switch (bsonType) {
         case BsonType.Null:
             bsonReader.ReadNull();
             return BsonNull.Value;
         case BsonType.Document:
             bsonReader.ReadStartDocument();
             var csharpNull = bsonReader.ReadBoolean("$csharpnull");
             bsonReader.ReadEndDocument();
             return csharpNull ? null : BsonNull.Value;
         default:
             var message = string.Format("Cannot deserialize BsonNull from BsonType {0}.", bsonType);
             throw new FileFormatException(message);
     }
 }
 public void TestBooleanFalse()
 {
     var json = "false";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.AreEqual(BsonType.Boolean, _bsonReader.ReadBsonType());
         Assert.AreEqual(false, _bsonReader.ReadBoolean());
         Assert.AreEqual(BsonReaderState.Done, _bsonReader.State);
     }
     Assert.AreEqual(json, BsonSerializer.Deserialize<bool>(json).ToJson());
 }
        private bool IsCSharpNullRepresentation(BsonReader bsonReader)
        {
            var bookmark = bsonReader.GetBookmark();
            bsonReader.ReadStartDocument();
            var bsonType = bsonReader.ReadBsonType();
            if (bsonType == BsonType.Boolean)
            {
                var name = bsonReader.ReadName();
                if (name == "_csharpnull" || name == "$csharpnull")
                {
                    var value = bsonReader.ReadBoolean();
                    if (value)
                    {
                        bsonType = bsonReader.ReadBsonType();
                        if (bsonType == BsonType.EndOfDocument)
                        {
                            bsonReader.ReadEndDocument();
                            return true;
                        }
                    }
                }
            }

            bsonReader.ReturnToBookmark(bookmark);
            return false;
        }
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 ) {
     var bsonType = bsonReader.CurrentBsonType;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull();
         return null;
     } else if (bsonType == BsonType.String) {
         return new CultureInfo(bsonReader.ReadString());
     } else if (bsonType == BsonType.Document) {
         bsonReader.ReadStartDocument();
         var name = bsonReader.ReadString("Name");
         var useUserOverride = bsonReader.ReadBoolean("UseUserOverride");
         bsonReader.ReadEndDocument();
         return new CultureInfo(name, useUserOverride);
     } else {
         var message = string.Format("Cannot deserialize CultureInfo from BsonType: {0}", bsonType);
         throw new FileFormatException(message);
     }
 }
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     var bsonType = bsonReader.CurrentBsonType;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull();
         return BsonNull.Value;
     } else if (bsonType == BsonType.Document) {
         bsonReader.ReadStartDocument();
         var csharpNull = bsonReader.ReadBoolean("$csharpnull");
         bsonReader.ReadEndDocument();
         return csharpNull ? null : BsonNull.Value;
     }
     throw new FileFormatException("Invalid representation for BsonNull");
 }
 public OXmlStyleElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
 {
     OXmlStyleElement element = new OXmlStyleElement();
     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() != "style")
                     throw new PBException($"invalid Type {type} when deserialize OXmlStyleElement");
                 break;
             case "id":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong Id value {bsonType}");
                 element.Id = bsonReader.ReadString();
                 break;
             case "name":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong Name value {bsonType}");
                 element.Name = bsonReader.ReadString();
                 break;
             case "styletype":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleType value {bsonType}");
                 element.StyleType = bsonReader.ReadString().zParseEnum<StyleValues>(ignoreCase: true);
                 break;
             case "aliases":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong Aliases value {bsonType}");
                 element.Aliases = bsonReader.ReadString();
                 break;
             case "customstyle":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong CustomStyle value {bsonType}");
                 element.CustomStyle = bsonReader.ReadBoolean();
                 break;
             case "defaultstyle":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong DefaultStyle value {bsonType}");
                 element.DefaultStyle = bsonReader.ReadBoolean();
                 break;
             case "locked":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong Locked value {bsonType}");
                 element.Locked = bsonReader.ReadBoolean();
                 break;
             case "semihidden":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong SemiHidden value {bsonType}");
                 element.SemiHidden = bsonReader.ReadBoolean();
                 break;
             case "stylehidden":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleHidden value {bsonType}");
                 element.StyleHidden = bsonReader.ReadBoolean();
                 break;
             case "unhidewhenused":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong UnhideWhenUsed value {bsonType}");
                 element.UnhideWhenUsed = bsonReader.ReadBoolean();
                 break;
             case "uipriority":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Int32)
                     throw new PBException($"wrong UIPriority value {bsonType}");
                 element.UIPriority = bsonReader.ReadInt32();
                 break;
             case "linkedstyle":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong LinkedStyle value {bsonType}");
                 element.LinkedStyle = bsonReader.ReadString();
                 break;
             case "basedon":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong BasedOn value {bsonType}");
                 element.BasedOn = bsonReader.ReadString();
                 break;
             case "nextparagraphstyle":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong NextParagraphStyle value {bsonType}");
                 element.NextParagraphStyle = bsonReader.ReadString();
                 break;
             case "styleparagraphproperties":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Document)
                     throw new PBException($"wrong StyleParagraphProperties value {bsonType}");
                 element.StyleParagraphProperties = ReadStyleParagraphProperties(bsonReader);
                 break;
             case "stylerunproperties":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Document)
                     throw new PBException($"wrong StyleRunProperties value {bsonType}");
                 element.StyleRunProperties = ReadStyleRunProperties(bsonReader);
                 break;
             default:
                 throw new PBException($"unknow Style value \"{name}\"");
         }
     }
     return element;
 }
 public void TestBooleanTrue() {
     var json = "true";
     using (bsonReader = BsonReader.Create(json)) {
         Assert.AreEqual(BsonType.Boolean, bsonReader.ReadBsonType());
         Assert.AreEqual(true, bsonReader.ReadBoolean());
         Assert.AreEqual(BsonReaderState.Done, bsonReader.State);
     }
     Assert.AreEqual(json, BsonSerializer.Deserialize<bool>(new StringReader(json)).ToJson());
 }
示例#15
0
 //_120509_173140 keep consistent
 static object ReadObject(BsonReader bsonReader)
 {
     switch (bsonReader.GetCurrentBsonType())
     {
         case BsonType.Array: return ReadArray(bsonReader); // replacement
         case BsonType.Binary: var binary = BsonSerializer.Deserialize<BsonValue>(bsonReader); return BsonTypeMapper.MapToDotNetValue(binary) ?? binary; // byte[] or Guid else self
         case BsonType.Boolean: return bsonReader.ReadBoolean();
         case BsonType.DateTime: return BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(bsonReader.ReadDateTime());
         case BsonType.Document: return ReadCustomObject(bsonReader); // replacement
         case BsonType.Double: return bsonReader.ReadDouble();
         case BsonType.Int32: return bsonReader.ReadInt32();
         case BsonType.Int64: return bsonReader.ReadInt64();
         case BsonType.Null: bsonReader.ReadNull(); return null;
         case BsonType.ObjectId: return bsonReader.ReadObjectId();
         case BsonType.String: return bsonReader.ReadString();
         default: return BsonSerializer.Deserialize<BsonValue>(bsonReader);
     }
 }
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     switch (bsonReader.CurrentBsonType) {
         case BsonType.Boolean:
             return bsonReader.ReadBoolean();
         case BsonType.Double:
             return bsonReader.ReadDouble() != 0.0;
         case BsonType.Int32:
             return bsonReader.ReadInt32() != 0;
         case BsonType.Int64:
             return bsonReader.ReadInt64() != 0;
         case BsonType.Null:
             bsonReader.ReadNull();
             return false;
         case BsonType.String:
             return XmlConvert.ToBoolean(bsonReader.ReadString().ToLower());
         default:
             var message = string.Format("Cannot deserialize Boolean from BsonType: {0}", bsonReader.CurrentBsonType);
             throw new FileFormatException(message);
     }
 }
 private static OXmlStyleRunProperties ReadStyleRunProperties(BsonReader bsonReader)
 {
     bsonReader.ReadStartDocument();
     OXmlStyleRunProperties value = new OXmlStyleRunProperties();
     while (true)
     {
         BsonType bsonType = bsonReader.ReadBsonType();
         if (bsonType == BsonType.EndOfDocument)
             break;
         string name = bsonReader.ReadName();
         switch (name.ToLower())
         {
             case "bold":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Bold value {bsonType}");
                 value.Bold = bsonReader.ReadBoolean();
                 break;
             case "boldcomplexscript":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties BoldComplexScript value {bsonType}");
                 value.BoldComplexScript = bsonReader.ReadBoolean();
                 break;
             case "caps":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Caps value {bsonType}");
                 value.Caps = bsonReader.ReadBoolean();
                 break;
             case "characterscale":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Int32)
                     throw new PBException($"wrong StyleRunProperties CharacterScale value {bsonType}");
                 value.CharacterScale = bsonReader.ReadInt32();
                 break;
             case "doublestrike":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties DoubleStrike value {bsonType}");
                 value.DoubleStrike = bsonReader.ReadBoolean();
                 break;
             case "emboss":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Emboss value {bsonType}");
                 value.Emboss = bsonReader.ReadBoolean();
                 break;
             case "emphasis":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleRunProperties Emphasis value {bsonType}");
                 value.Emphasis = bsonReader.ReadString().zParseEnum<EmphasisMarkValues>(ignoreCase: true);
                 break;
             case "fontsize":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleRunProperties FontSize value {bsonType}");
                 value.FontSize = bsonReader.ReadString();
                 break;
             case "fontsizecomplexscript":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleRunProperties FontSizeComplexScript value {bsonType}");
                 value.FontSizeComplexScript = bsonReader.ReadString();
                 break;
             case "imprint":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Imprint value {bsonType}");
                 value.Imprint = bsonReader.ReadBoolean();
                 break;
             case "italic":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Italic value {bsonType}");
                 value.Italic = bsonReader.ReadBoolean();
                 break;
             case "italiccomplexscript":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties ItalicComplexScript value {bsonType}");
                 value.ItalicComplexScript = bsonReader.ReadBoolean();
                 break;
             case "kern":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Int32)
                     throw new PBException($"wrong StyleRunProperties Kern value {bsonType}");
                 value.Kern = (uint)bsonReader.ReadInt32();
                 break;
             case "noproof":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties NoProof value {bsonType}");
                 value.NoProof = bsonReader.ReadBoolean();
                 break;
             case "outline":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Outline value {bsonType}");
                 value.Outline = bsonReader.ReadBoolean();
                 break;
             case "position":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleRunProperties Position value {bsonType}");
                 value.Position = bsonReader.ReadString();
                 break;
             case "runfonts":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Document)
                     throw new PBException($"wrong RunFonts value {bsonType}");
                 value.RunFonts = OXmlCommonSerializer.ReadRunFonts(bsonReader);
                 break;
             case "shadow":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Shadow value {bsonType}");
                 value.Shadow = bsonReader.ReadBoolean();
                 break;
             case "smallcaps":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties SmallCaps value {bsonType}");
                 value.SmallCaps = bsonReader.ReadBoolean();
                 break;
             case "snaptogrid":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties SnapToGrid value {bsonType}");
                 value.SnapToGrid = bsonReader.ReadBoolean();
                 break;
             case "spacing":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Int32)
                     throw new PBException($"wrong StyleRunProperties Spacing value {bsonType}");
                 value.Spacing = bsonReader.ReadInt32();
                 break;
             case "specvanish":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties SpecVanish value {bsonType}");
                 value.SpecVanish = bsonReader.ReadBoolean();
                 break;
             case "strike":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Strike value {bsonType}");
                 value.Strike = bsonReader.ReadBoolean();
                 break;
             case "texteffect":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleRunProperties TextEffect value {bsonType}");
                 value.TextEffect = bsonReader.ReadString().zParseEnum<TextEffectValues>(ignoreCase: true);
                 break;
             case "vanish":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties Vanish value {bsonType}");
                 value.Vanish = bsonReader.ReadBoolean();
                 break;
             case "verticaltextalignment":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleRunProperties VerticalTextAlignment value {bsonType}");
                 value.VerticalTextAlignment = bsonReader.ReadString().zParseEnum<VerticalPositionValues>(ignoreCase: true);
                 break;
             case "webhidden":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleRunProperties WebHidden value {bsonType}");
                 value.WebHidden = bsonReader.ReadBoolean();
                 break;
             default:
                 throw new PBException($"unknow PageMargin value \"{name}\"");
         }
     }
     bsonReader.ReadEndDocument();
     return value;
 }
 private static OXmlSpacingBetweenLines ReadSpacingBetweenLines(BsonReader bsonReader)
 {
     bsonReader.ReadStartDocument();
     OXmlSpacingBetweenLines value = new OXmlSpacingBetweenLines();
     while (true)
     {
         BsonType bsonType = bsonReader.ReadBsonType();
         if (bsonType == BsonType.EndOfDocument)
             break;
         string name = bsonReader.ReadName();
         switch (name.ToLower())
         {
             case "after":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong SpacingBetweenLines After value {bsonType}");
                 value.After = bsonReader.ReadString();
                 break;
             case "afterautospacing":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong SpacingBetweenLines AfterAutoSpacing value {bsonType}");
                 value.AfterAutoSpacing = bsonReader.ReadBoolean();
                 break;
             case "afterlines":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Int32)
                     throw new PBException($"wrong SpacingBetweenLines AfterLines value {bsonType}");
                 value.AfterLines = bsonReader.ReadInt32();
                 break;
             case "before":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong SpacingBetweenLines Before value {bsonType}");
                 value.Before = bsonReader.ReadString();
                 break;
             case "beforeautospacing":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong SpacingBetweenLines BeforeAutoSpacing value {bsonType}");
                 value.BeforeAutoSpacing = bsonReader.ReadBoolean();
                 break;
             case "beforelines":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Int32)
                     throw new PBException($"wrong SpacingBetweenLines BeforeLines value {bsonType}");
                 value.BeforeLines = bsonReader.ReadInt32();
                 break;
             case "line":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong SpacingBetweenLines Line value {bsonType}");
                 value.Line = bsonReader.ReadString();
                 break;
             default:
                 throw new PBException($"unknow PageMargin value \"{name}\"");
         }
     }
     bsonReader.ReadEndDocument();
     return value;
 }
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     var bsonType = bsonReader.CurrentBsonType;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull();
         return null;
     } else {
         return BsonBoolean.Create(bsonReader.ReadBoolean());
     }
 }
 private static OXmlStyleParagraphProperties ReadStyleParagraphProperties(BsonReader bsonReader)
 {
     bsonReader.ReadStartDocument();
     OXmlStyleParagraphProperties value = new OXmlStyleParagraphProperties();
     while (true)
     {
         BsonType bsonType = bsonReader.ReadBsonType();
         if (bsonType == BsonType.EndOfDocument)
             break;
         string name = bsonReader.ReadName();
         switch (name.ToLower())
         {
             case "adjustrightindent":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties AdjustRightIndent value {bsonType}");
                 value.AdjustRightIndent = bsonReader.ReadBoolean();
                 break;
             case "autospacede":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties AutoSpaceDE value {bsonType}");
                 value.AutoSpaceDE = bsonReader.ReadBoolean();
                 break;
             case "autospacedn":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties AutoSpaceDN value {bsonType}");
                 value.AutoSpaceDN = bsonReader.ReadBoolean();
                 break;
             case "bidi":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties BiDi value {bsonType}");
                 value.BiDi = bsonReader.ReadBoolean();
                 break;
             case "contextualspacing":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties ContextualSpacing value {bsonType}");
                 value.ContextualSpacing = bsonReader.ReadBoolean();
                 break;
             case "justification":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleParagraphProperties Justification value {bsonType}");
                 value.Justification = bsonReader.ReadString().zParseEnum<JustificationValues>(ignoreCase: true);
                 break;
             case "keeplines":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties KeepLines value {bsonType}");
                 value.KeepLines = bsonReader.ReadBoolean();
                 break;
             case "keepnext":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties KeepNext value {bsonType}");
                 value.KeepNext = bsonReader.ReadBoolean();
                 break;
             case "kinsoku":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties Kinsoku value {bsonType}");
                 value.Kinsoku = bsonReader.ReadBoolean();
                 break;
             case "mirrorindents":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties MirrorIndents value {bsonType}");
                 value.MirrorIndents = bsonReader.ReadBoolean();
                 break;
             case "outlinelevel":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Int32)
                     throw new PBException($"wrong StyleParagraphProperties OutlineLevel value {bsonType}");
                 value.OutlineLevel = bsonReader.ReadInt32();
                 break;
             case "overflowpunctuation":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties OverflowPunctuation value {bsonType}");
                 value.OverflowPunctuation = bsonReader.ReadBoolean();
                 break;
             case "pagebreakbefore":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties PageBreakBefore value {bsonType}");
                 value.PageBreakBefore = bsonReader.ReadBoolean();
                 break;
             case "snaptogrid":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties SnapToGrid value {bsonType}");
                 value.SnapToGrid = bsonReader.ReadBoolean();
                 break;
             case "spacingbetweenlines":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Document)
                     throw new PBException($"wrong StyleParagraphProperties SpacingBetweenLines value {bsonType}");
                 value.SpacingBetweenLines = ReadSpacingBetweenLines(bsonReader);
                 break;
             case "suppressautohyphens":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties SuppressAutoHyphens value {bsonType}");
                 value.SuppressAutoHyphens = bsonReader.ReadBoolean();
                 break;
             case "suppresslinenumbers":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties SuppressLineNumbers value {bsonType}");
                 value.SuppressLineNumbers = bsonReader.ReadBoolean();
                 break;
             case "suppressoverlap":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties SuppressOverlap value {bsonType}");
                 value.SuppressOverlap = bsonReader.ReadBoolean();
                 break;
             case "tabs":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Array)
                     throw new PBException($"wrong StyleParagraphProperties Tabs value {bsonType}");
                 value.Tabs = ReadTabs(bsonReader);
                 break;
             case "textalignment":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleParagraphProperties TextAlignment value {bsonType}");
                 value.TextAlignment = bsonReader.ReadString().zParseEnum<VerticalTextAlignmentValues>(ignoreCase: true);
                 break;
             case "textboxtightwrap":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleParagraphProperties TextBoxTightWrap value {bsonType}");
                 value.TextBoxTightWrap = bsonReader.ReadString().zParseEnum<TextBoxTightWrapValues>(ignoreCase: true);
                 break;
             case "textdirection":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleParagraphProperties TextDirection value {bsonType}");
                 value.TextDirection = bsonReader.ReadString().zParseEnum<TextDirectionValues>(ignoreCase: true);
                 break;
             case "toplinepunctuation":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties TopLinePunctuation value {bsonType}");
                 value.TopLinePunctuation = bsonReader.ReadBoolean();
                 break;
             case "widowcontrol":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties WidowControl value {bsonType}");
                 value.WidowControl = bsonReader.ReadBoolean();
                 break;
             case "wordwrap":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleParagraphProperties WordWrap value {bsonType}");
                 value.WordWrap = bsonReader.ReadBoolean();
                 break;
             default:
                 throw new PBException($"unknow PageSize value \"{name}\"");
         }
     }
     bsonReader.ReadEndDocument();
     return value;
 }