Advertisement
Danielos168

Untitled

Jun 3rd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1.     static class Serialzator
  2.     {
  3.         public static void Serialize<T>(string FileName, T obj)
  4.         {
  5.             if (obj is ISerializable)
  6.             {
  7.                 FileStream fs = new FileStream(FileName,FileMode.Create);
  8.                 File.Open(FileName,FileMode.Open);
  9.                 BinaryFormatter bf = new BinaryFormatter();
  10.                 bf.Serialize(fs, obj);
  11.                 fs.Close();
  12.             }
  13.  
  14.         }
  15.  
  16.  
  17.         public static T Deserialize<T>(string FileName)
  18.         {
  19.             FileStream fs = new FileStream(FileName,FileMode.Open);
  20.  
  21.             BinaryFormatter bf = new BinaryFormatter();
  22.  
  23.             T obj = (T)bf.Deserialize(fs);
  24.  
  25.             fs.Close();
  26.  
  27.             return obj;
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement