Skip to content

Commit f587c9e

Browse files
joey-beckerHorusiath
authored andcommitted
Support for FSharpSet<T> (#92)
* EnumerableSerializeFactory fixes * Update EnumerableSerializerFactory. Move null checks outside ObjectReader, allow private constructors. * Update EnumerableSerializerFactor to use Add method if exists, then IEnumerable<T> ctor. * Check for parameterless constructor before calling Activator.CreateInstance in EnumerableSerializerFactor * Test serialization of FSharpList<T> * Fix merge issues * Fix merge issues * Fix type in FSharpTests.cs
1 parent a2ddef9 commit f587c9e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Hyperion.Tests/FSharpTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public void CanSerializeFSharpList()
4444
Assert.Equal(expected, actual);
4545
}
4646

47+
[Fact]
48+
public void CanSerializeFSharpSet()
49+
{
50+
var expected = SetModule.OfArray(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
51+
Serialize(expected);
52+
Reset();
53+
var actual = Deserialize<object>();
54+
Assert.Equal(expected, actual);
55+
}
56+
4757
[Fact]
4858
public void CanSerializeSimpleDU()
4959
{

src/Hyperion/SerializerFactories/EnumerableSerializerFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
139139

140140
Func<object, int> countGetter = o => (int)countProperty.GetValue(o);
141141
ObjectReader reader = null;
142-
if (addMethod != null)
142+
if (HasParameterlessConstructor(type) && addMethod != null)
143143
{
144144
var add = CompileMethodToDelegate(addMethod, type, elementType);
145145
reader = (stream, session) =>

0 commit comments

Comments
 (0)