Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mcs/class/corlib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ test-vts:
$(vtsdir)/$(vts)TestLib/4.0/Address.cs
$(MCS) -target:library \
$(vtsdir)/$(vts)TestLib/5.0/Address.cs
$(MCS) -target:library \
$(vtsdir)/$(vts)TestLib/6.0/Address.cs
run-test-vts: test-vts
$(TEST_RUNTIME) $(RUNTIME_FLAGS) $(TEST_HARNESS) -noshadow \
$(vtsdir)/BinarySerializationOverVersions.exe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,22 @@ private void ReadObjectContent (BinaryReader reader, TypeMetadata metadata, long

info = metadata.NeedsSerializationInfo ? new SerializationInfo(metadata.Type, new FormatterConverter()) : null;

if (metadata.MemberNames != null)
if (metadata.MemberNames != null) {
for (int n=0; n<metadata.FieldCount; n++)
ReadValue (reader, objectInstance, objectId, info, metadata.MemberTypes[n], metadata.MemberNames[n], null, null);
else
for (int n=0; n<metadata.FieldCount; n++)
} else
for (int n=0; n<metadata.FieldCount; n++) {
if (metadata.MemberInfos [n] != null)
ReadValue (reader, objectInstance, objectId, info, metadata.MemberTypes[n], metadata.MemberInfos[n].Name, metadata.MemberInfos[n], null);
ReadValue (reader, objectInstance, objectId, info, metadata.MemberTypes[n], metadata.MemberInfos[n].Name, metadata.MemberInfos[n], null);
else if (BinaryCommon.IsPrimitive(metadata.MemberTypes[n])) {
// Since the member info is null, the type in this
// domain does not have this type. Even though we
// are not going to store the value, we will read
// it from the stream so that we can advance to the
// next block.
ReadPrimitiveTypeValue (reader, metadata.MemberTypes[n]);
}
}
}

private void RegisterObject (long objectId, object objectInstance, SerializationInfo info, long parentObjectId, MemberInfo parentObjectMemeber, int[] indices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ public void TestDroppedFieldWithOptionalAttribAndData () //eliminate AreaCode
Deserialize ("4.0", Serialize ("5.0"));
}

[Test]
public void TestDroppedPrimitiveTypeField() //eliminate Id (int)
{
Deserialize ("5.0", Serialize ("6.0"));
}

[Test]
public void TestAddedPrimitiveTypeField () //add Id (int)
{
Deserialize ("6.0", Serialize ("5.0"));
}

private static string Serialize (string assemblyVersion)
{
return SerializeOOP (SetEnvironment (assemblyVersion)); ;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Runtime.Serialization;

namespace VersionTolerantSerializationTestLib
{
[Serializable]
public class Address
{
private string Street;
private string City;
private string CountryCode;

[OptionalField (VersionAdded = 4)]
private string PostCode;

[OptionalField (VersionAdded = 5)]
private string AreaCode = "0";

[OptionalField (VersionAdded = 6)]
private int Id = 0;
}
}