Posted By

dmilligan on 04/30/15


Tagged

file FileStream BinaryFormatter


Versions (?)

LoadBinaryData


 / Published in: C#
 

A generic binary data loader.

  1. public T LoadBinaryData<T>(string path)
  2. {
  3. T data = default(T);
  4. if (File.Exists(path))
  5. {
  6. BinaryFormatter bf = new BinaryFormatter();
  7. using (FileStream fs = File.Open(path, FileMode.Open))
  8. {
  9. object o = bf.Deserialize(fs);
  10. fs.Close();
  11. if (o is T)
  12. data = (T)o;
  13. }
  14. }
  15. return data;
  16. }

Report this snippet  

You need to login to post a comment.