Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

private set on property deserialization problems #284

Copy link
Copy link
Closed
@juzamdjinn

Description

@juzamdjinn
Issue body actions

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.