Closed
Description
Hi , i try to deserialize an object with private set property and it returns 0 instead the right number
the example : ( i try in some way but no one works )
[MessagePackObject]
public class TransferCostDto : ITransferCosts
{
[Key(0)]
public ulong UploadQty { get; private set; }
[Key(1)]
public ulong DownloadQty { get; private set; }
[Key(2)]
private ulong _UploadQty;
[Key(3)]
private ulong _DownloadQty;
public ulong GetUploadQty()
{
return _UploadQty;
}
public ulong GetDownloadQty()
{
return _DownloadQty;
}
public virtual void AddUploadQty(ulong bytes)
{
_UploadQty += bytes;
UploadQty += bytes;
}
public virtual void AddDownloadQty(ulong bytes)
{
_DownloadQty += bytes;
DownloadQty += bytes;
}
}
[TestMethod]
public void SerializeTrasferCostsTest() {
var tr = new TransferCostDto();
tr.AddDownloadQty(3);
tr.AddUploadQty(10);
var trser = MessagePackSerializer.Serialize(tr , MessagePack.Resolvers.ContractlessStandardResolverAllowPrivate.Instance);
var trdeser = MessagePackSerializer.Deserialize<TransferCostDto>(trser);
var trser1 = MessagePackSerializer.Serialize(tr, MessagePack.Resolvers.DynamicObjectResolverAllowPrivate.Instance);
var trdeser1 = MessagePackSerializer.Deserialize<TransferCostDto>(trser1);
var trser3 = MessagePackSerializer.Serialize(tr, MessagePack.Resolvers.StandardResolverAllowPrivate.Instance);
var trdeser3 = MessagePackSerializer.Deserialize<TransferCostDto>(trser3);
trdeser.DownloadQty.Should().Be(3);
trdeser1.DownloadQty.Should().Be(3);
trdeser3.DownloadQty.Should().Be(3);
}
[MessagePack.Union(0, typeof(TransferCostDto))]
public interface ITransferCosts
{
ulong UploadQty { get; }
ulong DownloadQty { get; }
void AddUploadQty(ulong bytes);
void AddDownloadQty(ulong bytes);
}
Metadata
Metadata
Assignees
Labels
No labels