【问题标题】:Fixing 'obsolete' warning when using MsgPack.Cli修复使用 MsgPack.Cli 时的“过时”警告
【发布时间】:2017-04-14 02:25:52
【问题描述】:

我正在使用 MsgPack.Cli 为我创建的 Session 类编写自定义序列化程序。使用this tutorial on the MsgPack.Cli github page 创建类后,我收到以下警告:

警告:“MessagePackSerializer.MessagePackSerializer()”已过时:“请改用 MessagePackSerializer(SerializationContext)。”

我无法确定哪些更改可以解决此警告。我认为不需要 MessagePackSerializer 的知识来帮助我解决这个问题;我只是不明白警告的语法。

我的代码如下:

namespace Something_Networky
{
    public class Session
    {
        private int _n;
        public int n { get; }

        public Session(int n)
        {
            this._n = n;
        }
    }

    public class SessionSerializer : MessagePackSerializer<Session>
    {
        public SessionSerializer() : this(SerializationContext.Default) { }

        public SessionSerializer(SerializationContext context) // Warning displayed on this line
        {

        }

        protected override void PackToCore(Packer packer, Session value)
        {
            throw new NotImplementedException();
        }

        protected override Session UnpackFromCore(Unpacker unpacker)
        {
            throw new NotImplementedException();
        }
    }
}

感谢您的帮助。

【问题讨论】:

    标签: c# .net compiler-warnings msgpack


    【解决方案1】:

    我已经修复了错误。工作代码如下;我没有使用正确的参数调用基本构造函数。

    public class SessionSerializer : MessagePackSerializer<Session>
    {
        public SessionSerializer(SerializationContext context) : base(context) {
            throw new NotImplementedException();
        }
    
        protected override void PackToCore(Packer packer, Session objectTree)
        {
            throw new NotImplementedException();
        }
    
        protected override Session UnpackFromCore(Unpacker unpacker)
        {
            throw new NotImplementedException();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 2012-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-16
      相关资源
      最近更新 更多