我正在使用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();
}
}
}
感谢您的帮助。
答案 0 :(得分:0)
我已修复错误。工作代码如下;我没有用正确的参数调用基础构造函数。
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();
}
}