forked from amkovkov/GranuSightSoftware2
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Text.Json;
|
|
|
|
using GSS2.Core.Extentions;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace GSS2.Core.Abstractions;
|
|
|
|
public abstract record ServiceConfigurationBase
|
|
{
|
|
public virtual string ToString(string separator, int indent)
|
|
{
|
|
var strs = new List<string?>();
|
|
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}"));
|
|
}
|
|
} |