Skip to content

Commit 0cd15ae

Browse files
committed
Add HashtableConverter for Bson serialization
- Introduce PrimitiveType enum to represent primitive .NET types without string overhead. - Implement HashtableConverter to serialize/deserialize Hashtable entries while preserving original key/value types using cached type look‑ups and primitive type codes. - Register the new converter in BsonSerializerAdapter so it is used automatically. - Add unit test confirming that a Hashtable round‑trips with its original value types intact.
1 parent 6375ee3 commit 0cd15ae

4 files changed

Lines changed: 424 additions & 0 deletions

File tree

CoreRemoting.Tests/BsonSerializationTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System;
2+
using System.Collections;
23
using System.Data;
34
using System.Globalization;
5+
using System.IO;
46
using System.Linq;
57
using System.Net;
68
using System.Numerics;
9+
using System.Runtime.Serialization.Formatters.Binary;
710
using System.Text;
811
using CoreRemoting.RpcMessaging;
912
using CoreRemoting.Serialization.Bson;
@@ -267,4 +270,20 @@ void SerializeAndDeserialize<T>(T valueToSerialize)
267270
foreach (var encodingInfo in Encoding.GetEncodings())
268271
SerializeAndDeserialize(encodingInfo.GetEncoding());
269272
}
273+
274+
[Fact]
275+
public void BsonSerializerAdapter_should_deserialize_Hashtable_original_content_types()
276+
{
277+
var originalHashtable = new Hashtable();
278+
int originalValue = 10;
279+
originalHashtable["StoredValue"] = originalValue;
280+
281+
var serializer = new BsonSerializerAdapter();
282+
var serializedBytes = serializer.Serialize(originalHashtable);
283+
var deserializedHastable = serializer.Deserialize<Hashtable>(serializedBytes);
284+
var deserializedValue = deserializedHastable["StoredValue"];
285+
286+
Assert.Equal(originalValue, deserializedValue);
287+
Assert.True(deserializedValue is int);
288+
}
270289
}

CoreRemoting/Serialization/Bson/BsonSerializerAdapter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public BsonSerializerAdapter(BsonSerializerConfig config = null)
5757
new IPAddressConverter(),
5858
new IPEndPointConverter(),
5959
new IsoDateTimeConverter(),
60+
new HashtableConverter()
6061
]);
6162
}
6263

0 commit comments

Comments
 (0)