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

Skip to content
Merged
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
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