Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对象的序列化_C# - Fatal编程技术网

C# 对象的序列化

C# 对象的序列化,c#,C#,我正在使用 GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("string1",subobject1); info.AddValue("string2",subobject2); } 流中将存储什么?字符串也存储吗? 流中的确切存储格式如何???子对象1和子对象2

我正在使用

         GetObjectData(SerializationInfo info, StreamingContext context)
           {
               info.AddValue("string1",subobject1);
               info.AddValue("string2",subobject2);
           }
流中将存储什么?字符串也存储吗?
流中的确切存储格式如何???

子对象1和子对象2的值将被存储。是的,字符串也被存储,需要能够在反序列化过程中匹配传递给GetValue()的名称。

是的,字符串被存储为键,以便在后续反序列化过程中查找数据。它们将用于反序列化类的特殊构造函数中,如下所示:

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));
}

序列化对象存储在流中的确切格式是什么?正如Mark和Hans所说,这没有文档记录。我想您可以检查流的内容并尝试分析它,但我认为这不是一个好主意。为什么需要确切的格式?确切的存储格式是一个专有的实现细节,您不需要确切知道,因为它不能保证。如果需要已知格式,则使用其他序列化程序
BinaryFormatter
在此不做任何承诺。您无法得到这一点,因为二进制序列化格式没有文档记录,可能会发生更改。