public static ProfessionManager LoadProfessionManagerData() //, string fileLocation = PROFESSION_LOCATION) { JsonSerializerOptions options = GetJsonSerializerOptions(); options.Converters.Add(new ProfessionDataConverterWithTypeDiscriminator()); List <Type> professions = ProfessionManager.GetAllProfessions(); Dictionary <Type, ProfessionData> professionDatas = new Dictionary <Type, ProfessionData>(); foreach (Type item in professions) { string fileLocation = DATA_LOCATION + item.Name + ".json"; string s = File.ReadAllText(fileLocation); //File.WriteAllText(fileLocation, s); ProfessionData?pd = JsonSerializer.Deserialize <ProfessionData>(s, options); if (pd == null) { throw new Exception(); } professionDatas.Add(item, pd); } return(new ProfessionManager(professionDatas)); }
public static void SaveProfessionManagerData(ProfessionManager professionManager) //, string fileLocation = PROFESSION_LOCATION) { JsonSerializerOptions options = GetJsonSerializerOptions(); options.Converters.Add(new ProfessionDataConverterWithTypeDiscriminator()); List <Type> professions = ProfessionManager.GetAllProfessions(); foreach (Type item in professions) { ProfessionData pd = professionManager.GetProfessionData(item); string s = JsonSerializer.Serialize(pd, options); string fileLocation = DATA_LOCATION + item.Name + ".json"; File.WriteAllText(fileLocation, s); } }