我尝试在可序列化对象的子类上重写ISerializable.GetObjectData。我想用我自己的值替换其中一个值,但是我不知道怎么做。这是我尝试过的。
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
//replace the message value in info with my own value
info.AddValue("Message", this.Message);
}它抛出一个异常,声明为"Cannot add the same member twice to a SerializationInfo object"
发布于 2018-01-26 00:50:00
info.UpdateValue(name, value, type);请注意,常规.NET中不存在此API,但由于您的目标是.NET核心,因此您应该能够轻松地使用它。
https://stackoverflow.com/questions/48447996
复制相似问题