From 0a4b44f801d07b27943dc9a73686cb6f63b3c3f1 Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Sat, 13 Jan 2024 11:13:49 +0100 Subject: [PATCH] handle lists in config log output --- .../Services/MareConfigurationServiceServer.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosShared/Services/MareConfigurationServiceServer.cs b/MareSynchronosServer/MareSynchronosShared/Services/MareConfigurationServiceServer.cs index 24c9522..579c4fe 100644 --- a/MareSynchronosServer/MareSynchronosShared/Services/MareConfigurationServiceServer.cs +++ b/MareSynchronosServer/MareSynchronosShared/Services/MareConfigurationServiceServer.cs @@ -1,5 +1,6 @@ using MareSynchronosShared.Utils; using Microsoft.Extensions.Options; +using System.Collections; using System.Text; namespace MareSynchronosShared.Services; @@ -30,11 +31,20 @@ public class MareConfigurationServiceServer : IConfigurationService where StringBuilder sb = new(); foreach (var prop in props) { - sb.AppendLine($"{prop.Name} (IsRemote: {prop.GetCustomAttributes(typeof(RemoteConfigurationAttribute), true).Any()}) => {prop.GetValue(_config.CurrentValue)}"); + var isRemote = prop.GetCustomAttributes(typeof(RemoteConfigurationAttribute), true).Any(); + var getValueMethod = GetType().GetMethod(nameof(GetValue)).MakeGenericMethod(prop.PropertyType); + var value = isRemote ? getValueMethod.Invoke(this, new[] { prop.Name }) : prop.GetValue(_config.CurrentValue); + if (typeof(IEnumerable).IsAssignableFrom(prop.PropertyType) && !typeof(string).IsAssignableFrom(prop.PropertyType)) + { + var enumVal = (IEnumerable)value; + value = string.Empty; + foreach (var listVal in enumVal) + { + value += listVal.ToString() + ", "; + } + } + sb.AppendLine($"{prop.Name} (IsRemote: {isRemote}) => {value}"); } - - sb.AppendLine(_config.ToString()); - return sb.ToString(); } }