using System.Text.Json; using System.Text.Json.Serialization; namespace Nerfed.Compiler; public class Project { public string Name { get; set; } public static bool Create(string path, string name, out Project project) { project = null; // Create project file. project = new Project { Name = name, }; Save(project, path); return true; } public static bool Save(Project project, string projectFilePath) { string jsonString = JsonSerializer.Serialize(project, ProjectContext.Default.Project); File.WriteAllText(projectFilePath, jsonString); return true; } public static bool Open(string path, out Project project) { string jsonString = File.ReadAllText(path); project = JsonSerializer.Deserialize(jsonString, ProjectContext.Default.Project); if (project == null) { Console.WriteLine($"ERROR: Could not open {typeof(Project)}."); return false; } return true; } } [JsonSerializable(typeof(Project))] public partial class ProjectContext : JsonSerializerContext { }