Skip to content

Commit

Permalink
Merge pull request #1785 from epitka/master
Browse files Browse the repository at this point in the history
fixing issue with backing field naming and serialization failing
  • Loading branch information
AArnott committed Mar 31, 2024
2 parents 09dd954 + dfe2717 commit 43f1b1c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2019,19 +2019,6 @@ bool AddEmittableMemberOrIgnore(bool isIntKeyMode, EmittableMember member, bool

if (len != 0)
{
if (len != 1)
{
if (ctorEnumerator != null)
{
ctor = null;
break;
}
else
{
throw new MessagePackDynamicObjectResolverException("duplicate matched constructor parameter name:" + type.FullName + " parameterName:" + item.Name + " parameterType:" + item.ParameterType.Name);
}
}

paramMember = hasKey.First().Value;
if (item.ParameterType.IsAssignableFrom(paramMember.Type) && paramMember.IsReadable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,43 @@ public TestConstructor2(int x, int y, int z)
}
}

public class TestConstructor3
{
private Guid x;
private Guid y;

public TestConstructor3(Guid x, Guid y)
{
this.x = x;
this.y = y;
this.CalledConstructorParameterCount = 2;
}

public int CalledConstructorParameterCount { get; }

public Guid X
{
get => this.x;
set => this.x = value;
}

public Guid Y
{
get => this.y;
set => this.y = value;
}
}

[Fact]
public void UseConstructor3()
{
var ctor = new TestConstructor3(Guid.NewGuid(), Guid.NewGuid());
var bin = MessagePackSerializer.Serialize(ctor, ContractlessStandardResolverAllowPrivate.Options);
var r = MessagePackSerializer.Deserialize<TestConstructor3>(bin, ContractlessStandardResolverAllowPrivate.Options)!;

r.CalledConstructorParameterCount.Is(2);
}

[Fact]
public void UseConstructor()
{
Expand All @@ -95,6 +132,16 @@ public void UseConstructor()
r.CalledConstructorParameterCount.Is(3);
}

[Fact]
public void UseConstructor2()
{
var ctor = new TestConstructor1(10, 20, 30);
var bin = MessagePackSerializer.Serialize(ctor, ContractlessStandardResolver.Options);
var r = MessagePackSerializer.Deserialize<TestConstructor1>(bin, ContractlessStandardResolver.Options);

r.CalledConstructorParameterCount.Is(3);
}

[Fact]
public void IgnorePropertiesWithoutConstructorArgument()
{
Expand Down

0 comments on commit 43f1b1c

Please sign in to comment.