Skip to content

Commit

Permalink
Add test for generic class containing property with init setter
Browse files Browse the repository at this point in the history
Repro for failure as reported in MessagePack-CSharp#1134
  • Loading branch information
AArnott committed Nov 23, 2020
1 parent d87428d commit 908ac7b
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ public void DefaultValueIntKeyStructWithExplicitConstructorSetPropertyTest()
Assert.Equal(-98, instance.Prop2);
}

#if NET5_0
[Fact]
public void RoundtripGenericClass()
{
var person = new GenericPerson<int> { Name = "bob" };
byte[] msgpack = MessagePackSerializer.Serialize(person, MessagePackSerializerOptions.Standard);
var deserialized = MessagePackSerializer.Deserialize<GenericPerson<int>>(msgpack, MessagePackSerializerOptions.Standard);
Assert.Equal(person.Name, deserialized.Name);
}
#endif

[MessagePackObject(true)]
public class DefaultValueStringKeyClassWithoutExplicitConstructor
{
Expand Down Expand Up @@ -597,6 +608,15 @@ public class DerivedClass : BaseClass
[DataMember]
public string Name { get; set; }
}

#if NET5_0
[MessagePackObject]
public class GenericPerson<T>
{
[Key(0)]
public string Name { get; init; }
}
#endif
}
}

Expand Down

0 comments on commit 908ac7b

Please sign in to comment.