Пример #1
0
        /// <summary>
        /// This is read serialized object fucntion
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static T ReadSerializedObjectFile <T>(string fileName)
        {
            try
            {
                T result;
                using (var reader = new StreamReader(fileName))
                {
                    result = Ultilities.deserializeObject <T>(reader.ReadToEnd());
                }

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(default(T));
            }
        }
Пример #2
0
 /// <summary>
 /// This it write serialized object
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="fileName"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static bool WriteSerialObjectToFile <T>(string fileName, T data)
 {
     try
     {
         if (File.Exists(fileName))
         {
             File.Delete(fileName);
         }
         TextWriter writer       = new StreamWriter(fileName);
         string     writenString = Ultilities.serializeObject <T>(data);
         writer.Write(writenString);
         writer.Close();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }