/// <summary> /// Tries to read a JSON file from disk /// </summary> /// <param name="FileName">File to read from</param> /// <param name="Result">On success, receives the parsed object</param> /// <returns>True if the file was read, false otherwise</returns> public static bool TryRead(FileReference FileName, out JsonObject Result) { if (!FileReference.Exists(FileName)) { Result = null; return(false); } string Text = FileReference.ReadAllText(FileName); return(TryParse(Text, out Result)); }
/// <summary> /// Read a JSON file from disk and construct a JsonObject from it /// </summary> /// <param name="File">File to read from</param> /// <returns>New JsonObject instance</returns> public static JsonObject Read(FileReference File) { string Text = FileReference.ReadAllText(File); try { return(Parse(Text)); } catch (Exception Ex) { throw new JsonParseException("Unable to parse {0}: {1}", File, Ex.Message); } }
/// <summary> /// Read a JSON object from a file on disk /// </summary> /// <typeparam name="T">The type of the object to load</typeparam> /// <param name="Location">The location of the file to read</param> /// <returns>The deserialized object</returns> public static T Load <T>(FileReference Location) { string Text; try { Text = FileReference.ReadAllText(Location); } catch (Exception Ex) { throw new Exception(String.Format("Unable to read '{0}'", Location), Ex); } return(Deserialize <T>(Text)); }