Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //dictionary to byte[]
- public byte[] ObjectToByteArray<T>(this T obj)
- {
- MemoryStream m = new MemoryStream();
- if (obj != null)
- {
- BinaryFormatter b = new BinaryFormatter();
- b.Serialize(m, obj);
- }
- return m.ToArray();
- }
- //byte[] to dictionary
- //T == the type (object) to return
- public T ByteArrayToObject<T>(this byte[] arrBytes)
- {
- if (arrBytes == null || arrBytes.Length < 1)
- return default(T);
- BinaryFormatter binForm = new BinaryFormatter();
- //Whatever object you are trying to Deserialize it too
- T obj = (T)binForm.Deserialize(new MemoryStream(arrBytes));
- return obj;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement