using System.Collections; using System.Text.Json; using GSS2.Core.Extensions; using Microsoft.Extensions.Configuration; namespace GSS2.Core.Abstractions; public abstract record ServiceConfigurationBase { public virtual string ToString(string separator, int indent) { var strs = new List(); foreach (var prop in GetType().GetProperties()) { if (prop.GetMethod?.IsStatic != false) continue; var value = prop.GetValue(this); string? strValue = value switch { string str => str, IConfigurationSection configurationSection => $"\n{(configurationSection.AsDictionary() as IDictionary).ToString(separator, indent * 2)}", IDictionary dictionary => $"\n{dictionary.ToString(separator, indent * 2)}", IEnumerable enumerable => $"\n{enumerable.ToString(separator, indent * 2)}", object obj => obj?.ToString(), _ => null }; strs.Add($"{prop.Name}: {strValue}"); } return string.Join(separator, strs.Select(s => $"{new string(' ', indent)}{s}")); } }