using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; namespace GB5Shared.DTO.Framework.CommonConfig { public sealed class DataBase { private static readonly Lazy _instance = new Lazy(() => new DataBase()); private static readonly string filePath = @"C:\TextFile\DataBase.txt"; // Declare 200+ fields public string DataBaseType { get; set; } public string ServerName { get; set; } // Add more fields as needed... private DataBase() { LoadFromJson(); } public static DataBase Instance => _instance.Value; private void LoadFromJson() { if (File.Exists(filePath)) { try { string json = File.ReadAllText(filePath); JsonConvert.PopulateObject(json, this); // ✅ Populate instance instead of creating new object } catch (Exception) { DataBaseType = "SQL"; } } } public void SaveToJson() { try { string json = JsonConvert.SerializeObject(this, Formatting.Indented); File.WriteAllText(filePath, json); } catch (Exception) { DataBaseType = "SQL"; } } } }