Usage:
Code Snippet
- // Inits
- // Serialize
- string data = SerializeObject<CustomClass>(instance);
- // DeSerialize
- CustomClass instance = DeSerializeObject<CustomClass>(data);
End of Code Snippet
Code Snippet
- // NOTE: The result of serializing an object with BinaryFormatter is an octet stream, not a string.
- // If we encode the serialized object with Base64, we will get our string.
- public static string SerializeObject<T>(T toSerialize)
- {
- System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
- if (!toSerialize.GetType().IsSerializable)
- {
- }
- {
- return Convert.ToBase64String(ms.ToArray());
- }
- }
- public static T DeSerializeObject<T>(string data)
- {
- byte[] bytes = Convert.FromBase64String(data);
- {
- }
- }
End of Code Snippet
No comments:
Post a Comment