开发者

Serialization of an object

I am Serialing an object using

         GetObjectData(SerializationInfo info, StreamingContext context)
           {
               info.AddValue("string1",subobject1);
               in开发者_开发百科fo.AddValue("string2",subobject2);
           }

what will be stored in stream? do the strings also store? How will be the exact storage format in Stream??


The subobject1 and subobject2 values will be stored. Yes, the string are also stored, needed to be able to match the name passed to GetValue() during deserialization.


Yes, the strings are stored as the keys by which to look up the data during the subsequent deserialization. They would be used in a special constructor of the class being deserialized, something like this:

public YourClass(SerializationInfo info, StreamingContext ctxt)    
{
    //Get the values from info and assign them to the appropriate properties        
    this.String1 = (String)info.GetValue("string1", typeof(string));
    this.String2 = (String)info.GetValue("string2", typeof(string));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜