.NET Deserialisation with OnDeserializing and OnDeserialized

前端 未结 3 671
一向
一向 2020-12-28 17:02

I use a simple class that is serializable. It has a constructor for the deserialization:

protected MyClass(SerializationInfo info, StreamingContext context)
         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 17:15

    [OnDeserializing] Indicates a method to be called just before deserialization [OnDeserialized] Indicates a method to be called just after deserialization

    An [OnDeserializing] method acts as a pseudoconstructor for deserialization, and it is useful for initializing fields excluded from serialization:

    [OnDeserializing] and [OnDeserialized] Deserialization bypasses all your normal constructors as well as field initializers. This is of little consequence if every field partakes in serialization, but it can be problematic if some fields are excluded via [NonSerialized].

    I took this text from Albahari book C# 5.0 in nutshell page 713 check it out online a lot of example and description about your problem.

    Thanks

提交回复
热议问题