diff --git a/Salar.Bois.Tests/ObjectsTest.cs b/Salar.Bois.Tests/ObjectsTest.cs index 94203f8..518db17 100644 --- a/Salar.Bois.Tests/ObjectsTest.cs +++ b/Salar.Bois.Tests/ObjectsTest.cs @@ -241,7 +241,6 @@ public void HierarchyObjects2Test() AssertionHelper.AssertMembersAreEqual(init.KidNull, final.KidNull); AssertionHelper.AssertMembersAreEqual(init.KidValue, final.KidValue); init.KidNull.Should().Be.EqualTo(final.KidNull); - init.KidValue.Should().Be.EqualTo(final.KidValue); } [TestMethod] diff --git a/Salar.Bois/BoisSerializer.cs b/Salar.Bois/BoisSerializer.cs index c1027d4..261de34 100644 --- a/Salar.Bois/BoisSerializer.cs +++ b/Salar.Bois/BoisSerializer.cs @@ -176,37 +176,26 @@ private void WriteObject(BinaryWriter writer, BoisMemberInfo boisMemInfo, object { if (obj == null) { - // null indicator - WriteValue(writer, true); - return; + // null indicator + WriteNullableType(writer, true); + return; } - _serializeDepth++; var type = obj.GetType(); var boisType = _typeCache.GetTypeInfo(type, true); var boisTypeInfo = boisType as BoisTypeInfo; - // Use this member info if avaiable. it is more accurate because it came from the object holder, - // not the object itseld. - if (boisMemInfo != null) - { - if (boisMemInfo.IsContainerObject && boisMemInfo.IsNullable) - { - //This is a nullable struct and is not null - WriteValue(writer, false); - } - } - else - { - if (boisType.IsContainerObject && boisType.IsNullable) - { - //This is a nullable struct and is not null - WriteValue(writer, false); - } - } - - if (boisTypeInfo != null) + _serializeDepth++; + // Use this member info if avaiable. it is more accurate because it came from the object holder, + // not the object itseld. + if (boisMemInfo.IsContainerObject && boisMemInfo.IsNullable) + { + //This is a nullable struct and is not null + WriteNullableType(writer, false); + } + + if (boisTypeInfo != null) { // writing the members for (int i = 0; i < boisTypeInfo.Members.Length; i++) @@ -857,10 +846,10 @@ private object ReadMember(BinaryReader reader, Type memType) private object ReadMember(BinaryReader reader, BoisMemberInfo memInfo, Type memType) { - if ((memInfo.IsNullable && memInfo.IsContainerObject) || - (memInfo.IsNullable && !memInfo.IsSupportedPrimitive && (!memInfo.IsContainerObject || memInfo.IsStruct))) - { - bool isNull = reader.ReadByte() != 0; + if ((memInfo.IsNullable && memInfo.IsContainerObject) || + (memInfo.IsNullable && !memInfo.IsSupportedPrimitive && (!memInfo.IsContainerObject || memInfo.IsStruct))) + { + bool isNull = reader.ReadByte() != 0; if (isNull) {