using Newtonsoft.Json; using System.Text; public class Config { [JsonProperty("serial")] public string Serial { get; set; } = "<серийный номер не указан>"; [JsonProperty("light-version")] public int LightVersion { get; set; } = 2; [JsonProperty("electronic-version")] public int ElectronicVersion { get; set; } = 2; [JsonProperty("sensor-positive-value")] public int SensorPositiveValue { get; set; } = 0; [JsonProperty("start-server")] public bool StartServer { get; set; } = false; [JsonProperty("server-password")] public string ServerPassword { get; set; } = "1234"; public void UpdateFromJson(string json) { JsonConvert.PopulateObject(json, this); } public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine($"serial: {Serial}"); sb.AppendLine($"light-version: {LightVersion}"); sb.AppendLine($"electronic-version: {ElectronicVersion}"); sb.AppendLine($"sensor-positive-value: {SensorPositiveValue}"); sb.AppendLine($"start-server: {StartServer}"); sb.Append($"server-password: {ServerPassword}"); return sb.ToString(); } }