示例#1
0
 /// <summary>
 /// Write an object to a file.
 /// </summary>
 /// <param name="obj">The object that needs to be written to storage.</param>
 /// <param name="path">The absolute path.</param>
 public bool writeFile(object obj, string path)
 {
     try
     {
         string result = new JSONManager().objectToString(obj);
         System.IO.File.WriteAllText(path, result);
         return(true);
     }
     catch (Exception e)
     {
         Debug.Log(e.Message);
         return(false);
     }
 }
示例#2
0
 /// <summary>
 /// Read a file from storage and convert it to an object.
 /// </summary>
 /// <param name="path">The absolute path of the object.</param>
 /// <param name="type">The type of the object that is converted into.</param>
 /// <returns>The read object.</returns>
 public object readFile(string path, Type type)
 {
     try
     {
         JSONManager jm      = new JSONManager();
         string      result  = System.IO.File.ReadAllText(path);
         MethodInfo  method  = typeof(JSONManager).GetMethod("stringToObject");
         MethodInfo  generic = method.MakeGenericMethod(type);
         return(generic.Invoke(jm, new object[] { result }));
     }
     catch (Exception e)
     {
         Debug.Log(e.Message);
         return(null);
     }
 }