Example #1
0
 public static void Display <T>(this T settings) where T : ISettings, IDescription
 {
     MyConsole.WriteNewLineGreen($"Current Settings");
     foreach (var setting in settings.GetType().GetProperties())
     {
         var description = settings.GetPropertyDescription(setting.Name);
         var value       = setting.GetValue(settings);
         MyConsole.WriteLine($"{description,-40} {value}");
     }
 }
Example #2
0
        public static void SaveToFile <T>(this T settings) where T : ISettings
        {
            MyConsole.WriteNewLineGreen("Введите имя файла для сохранения настроек");
            var fileName = MyConsole.ReadLine();
            var dirPath  = AppContext.BaseDirectory + "/settings";
            var filePath = $"{dirPath}/{fileName}.json";

            Directory.CreateDirectory(dirPath);
            string jsonString = settings.SaveToStr();

            File.WriteAllText(filePath, jsonString);
            MyConsole.WriteNewLineGreen($"Настройки сохранены в файл {fileName}.json");
        }