From aeea5ad0df546ef7c6b4f19edc3f67d0d2203a3a Mon Sep 17 00:00:00 2001 From: Felipe Machado Date: Thu, 23 Nov 2023 19:47:08 -0300 Subject: [PATCH] Little refactogin in Serialize method --- NetDot/DotNotation.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/NetDot/DotNotation.cs b/NetDot/DotNotation.cs index a9ffe55..e901504 100644 --- a/NetDot/DotNotation.cs +++ b/NetDot/DotNotation.cs @@ -97,9 +97,9 @@ private static void StoreArrayItem(List list, Member member, object ite return JsonConvert.DeserializeObject(json, settings); } - public static string Serialize(object? o, string? prefix = null, DotNotationSettings? settings = null) { + public static string Serialize(object? o, string prefix = "", DotNotationSettings? settings = null) { settings ??= DotNotationSettings.Default; - string dot(string? s) => s is null ? "" : s + settings.DotConnector; + string dot(string? s) => string.IsNullOrEmpty(s) ? "" : s + settings.DotConnector; if (o is null) return ""; var sb = new StringBuilder(); if (typeof(IDictionary).IsAssignableFrom(o.GetType())) { @@ -124,8 +124,7 @@ public static string Serialize(object? o, string? prefix = null, DotNotationSett sb.Append(Serialize(v, $"{dot(prefix)}{prop.Name}", settings)); } } else { - if (prefix is not null) - sb.Append(WriteEntry(prefix, o, settings)); // $"{prefix}={o}"); + sb.Append(WriteEntry(prefix, o, settings)); // $"{prefix}={o}"); } return sb.ToString(); }