最常用的两个方法:

Deserialize(Stream) 将指定的流反序列化成对象
Serialize(Stream, Object) 将对象序列化到给定的流

两个常用的属性:

Serializable 表示可以被序列化
NonSerializable 屏蔽被序列化
  1. [Serializable]
  2. private class Person  //用Serializable做了标记,标识可以被序列化

[NonSerialized] private string _name; //用NonSerialized做了标记,标识该字段屏蔽序列化

序列化例子:
                     Dim pFormatter As New BinaryFormatter()
        Dim pStream As New MemoryStream()
        Try
            pFormatter.Serialize(pStream, Me.mConfig)
            Dim a = pStream.GetBuffer()
            pStream.Close()
            Return SuccessFailResult(Of Byte()).createSuccessResult(a)
        Catch ex As Exception
            Return SuccessFailResult(Of Byte()).createFailResultAutoConcat(“序列化罐配置对像失败”, ex)
        End Try
反序列化例子:
        Dim pFormatter As New BinaryFormatter()
        Dim pStream As New MemoryStream(pConfigBytes)
        Try
            Dim pObject = CType(pFormatter.Deserialize(pStream), Config_Tank)
            pStream.Close()
            Return SuccessFailResult(Of Config_Tank).createSuccessResult(pObject)
        Catch ex As Exception
            Return SuccessFailResult(Of Config_Tank).createFailResultAutoConcat(“反序列化罐配置对像失败”, ex)
        End Try