ideserializationcallback

IDeserializationCallback vs OnDeserializedAttribute

孤人 提交于 2020-01-01 08:17:09
问题 As far as I understand, the IDeserializationCallback interface and the OnDeserialized event can both be used when an object needs to perform some task after being deserialized. IDeserializationCallback: [Serializable] public class Foo : IDeserializationCallback { public void OnDeserialization(object sender) { // initialize unserialized fields etc. } } OnDeserialized event: [Serializable] public class Foo { [OnDeserialized] public void OnDeserialized(StreamingContext context) { // initialize

Can OnDeserializedAttribute be used instead of IDeserializationCallback interface?

不打扰是莪最后的温柔 提交于 2019-12-22 05:07:29
问题 As MSDN states here, it can. But I've spent 2 hours digging mscorlib code, because in some cases the BinaryFormatter called my method marked with OnDeserialized BEFORE deserialization constructor. That is, the order was OnDeserializing(StreamingContext context) OnDeserialized(StreamingContext context) .ctor(SerializationInfo info, StreamingContext context) While I was expecting it to be OnDeserializing(StreamingContext context) .ctor(SerializationInfo info, StreamingContext context)

Can OnDeserializedAttribute be used instead of IDeserializationCallback interface?

泄露秘密 提交于 2019-12-22 05:07:08
问题 As MSDN states here, it can. But I've spent 2 hours digging mscorlib code, because in some cases the BinaryFormatter called my method marked with OnDeserialized BEFORE deserialization constructor. That is, the order was OnDeserializing(StreamingContext context) OnDeserialized(StreamingContext context) .ctor(SerializationInfo info, StreamingContext context) While I was expecting it to be OnDeserializing(StreamingContext context) .ctor(SerializationInfo info, StreamingContext context)

Can OnDeserializedAttribute be used instead of IDeserializationCallback interface?

浪子不回头ぞ 提交于 2019-12-05 05:34:37
As MSDN states here , it can. But I've spent 2 hours digging mscorlib code, because in some cases the BinaryFormatter called my method marked with OnDeserialized BEFORE deserialization constructor. That is, the order was OnDeserializing(StreamingContext context) OnDeserialized(StreamingContext context) .ctor(SerializationInfo info, StreamingContext context) While I was expecting it to be OnDeserializing(StreamingContext context) .ctor(SerializationInfo info, StreamingContext context) OnDeserialized(StreamingContext context) And the final point. When I implemented IDeserializationCallback

IDeserializationCallback vs OnDeserializedAttribute

房东的猫 提交于 2019-12-04 00:35:36
As far as I understand, the IDeserializationCallback interface and the OnDeserialized event can both be used when an object needs to perform some task after being deserialized. IDeserializationCallback: [Serializable] public class Foo : IDeserializationCallback { public void OnDeserialization(object sender) { // initialize unserialized fields etc. } } OnDeserialized event: [Serializable] public class Foo { [OnDeserialized] public void OnDeserialized(StreamingContext context) { // initialize unserialized fields etc. } } Are there any specific pros/cons or scenarios where you would choose one